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

const int MAXN = 1e6, MAXBIT = 30;
int cnt[MAXBIT + 4];

int popcnt(int t){
    int ans = 0;
    for(int i = 0; i <= MAXBIT; i++){
        ans += ((t >> i) & 1);
        //cout << i <<  " - > " << ans << " " << ((t >> i) & 1) << "\n";
    }
    return ans;
}

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n, k; cin >> n >> k;
    vector<int>a(n);
    for(auto &i : a){
        cin >> i;
        for(int j = 30; j >= 0; j--){
            //cout << i << " " << j << " " <<(i >> j) & 1 << "\n";
            if((i >> j) & 1){
                cnt[j + 1]++;
                break;
            }
        }
    }
    int bestrbit = 0;
    for(int bit = 30; bit >= 0; bit--){
        if(cnt[bit] >= k){
            bestrbit = bit;
            break;
        }
    }
    //cout << bestrbit << "\n";
    int ans = -1;
    for(int bit = bestrbit; bit > 0; bit--){

        int _or = 0, _and = -1;
        int br = 0;int t = -1;
        for(int l = 0, r = -1; l < n;){
            _or = 0;
            if(br >= k)break;
            //cout << l << " " << r << " " << " " << br << endl;
            //cout << "NEW: \n";
            t = -1;
            while(r + 1 < n){
                //cout << "iuert" << endl;
                //cout << "r = " << r << "\n";
                r++;
                for(int check = bestrbit; check >= bit; check--){
                    //if((t >> (check - 1)) & 1)continue;
                    if((a[r] >> (check - 1)) & 1){
                        int t1 = (1 << (check - 1));
                        //cout << check << " " << t1 << endl;
                        t = (t == -1 ? t1 : (t | t1));//otbelqzvam che imam tozi bit
                    }
                }
                _or |= a[r];//cout << "kjhgf" << endl;
                //cout << t<< endl;
                ///cout << t << " - > " << popcnt(t) << endl;;
                if(popcnt(t) >= bestrbit - bit + 1 && t != -1)break;
            }

            //cout << l << " , " << r<< endl;
            if(_and == -1)_and = _or;
            else _and &= _or;
            //cout << "_and: = " << _and << " , _or: " << _or << endl;
            l = r + 1;
            //cout << "br++" << endl;
            br++;
        }/// maj trqba nqkude da checkvam dali sum stignal do kraq uspesho!!!
        //cout << br << endl;
        //if(popcnt(t) >= bestrbit - bit + 1 && t != -1 && br >= k)
            ans = max(ans, _and);

    }
    cout << ans << endl;
}

