#include <bits/stdc++.h>
using namespace std;

using ll = long long;

int main() {
    int N, K;

    cin >> N >> K;

    vector<ll> A (N);

    for (int i = 0; i < N; i++) cin >> A[i]; 
    


    vector<vector<bool>> logN (N, vector<bool> (32, false));

    vector<ll> logs (32, 0);

    for (int i = 0; i < N; i++) {
            
        if (A[i] % 2 == 1) {
            logN[i][0] = true;
        }
            
    }


    for (int i = 0; i < N; i++) {
        for (int j = 31; j >= 0; j--) {

            int a = log2(A[i]);

            if (a == j) {
                logN[i][j] = true;
                A[i] -= 1 << a;
                logs[j]++;
            }
        }
    }
    
   
    

    ll maxLog = 0;


    for (int i = 31; i >= 0; i--) {
        if (logs[i] >= K) {
            
            maxLog = i;
            break;
        }
    }

    ll ans = 1 << maxLog;

    for (int i = maxLog - 1; i >= 0; i--) {
        if (logs[i] >= K) {
            
            ll remainingLogs = logs[maxLog] - K;             
            
            
            int forNow = 1;

            vector<bool> has (K);

            int current = 0;

            for (int j = 0; j < N; j++) {
                //cout << remainingLogs << "\n" << forNow << "\n";
                

                if (logN[j][i] && forNow < 2) {
                    has[current] = true;
                }

                if (logN[j][i + 1]) {
                    current++;
                }
                

                if (remainingLogs < -1) {
                    break;
                }
            }

            bool flag = false;

            for (int i = 0; i < K; i++) {
                if (has == 0) flag = true; break;
            }

            if (remainingLogs >= 0 && !flag) {
                ans += 1 << i; 
            }
        }
    }

    cout << ans;

}