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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = (cin >> n,n);
    int K = (cin >> K,K);

    vector<int> A(n);
    for (int i = 0; i < n; i++)
    {
        cin >> A[i];
    }
    

    vector<int> DP[2]; // [DP[i],i]
    int ans = 0;
    int curr = 0;

    for (int i = 0; i < n; i++)
    {
        DP[0].push_back(i);
        DP[1].push_back(i);
    }
    
    for (int power = 1073741824;power > 0;power /= 2){
        int last = -1;
        for (int i = 0; i < n; i++)
        {
            if(A[i]&power){
                last = i;
            }
            
            DP[1-curr][i] = last;
        }
        for (int i = 0; i < n; i++)
        {
            DP[1-curr][i] = min(DP[1-curr][i],DP[curr][i]);
        }
        int numOfSegments = 0;
        for (int i = n-1;(i>=0)&&(DP[1-curr][i] >= 0); i = DP[1-curr][i]-1){
            numOfSegments++;
        }
        if (numOfSegments >= K){
            curr = 1-curr;
            ans |= power;
        }
    }
    cout << ans << endl;
}