#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll , ll>
void solve(){
    ll n,k;
    cin >>n >>k;
    vector<ll> cnt(31) ,check(n,1), pc(n);
    ll ans = 0;
    vector< vector<ll> > v(31,vector<ll>(n));
    for(ll i = 0 ; i < n; i++){
        ll x;
        cin >>x;
        for(ll j = 0; j < 31; j++){
            v[j][i] = (x&1);
            x /= 2;
            cnt[j] += v[j][i];
        }
    }
    for(ll i = 30; i >= 0; i--){
        if(cnt[i] >= k){
            ll coun = 0, hmm = 0;
            for(ll j = 0; j < n; j++){
                if(check[j]){
                    hmm = (1|hmm);
                }
                if(v[i][j]){
                    hmm = (2|hmm);
                }
                if(hmm == 3){
                    hmm = 0;
                    coun++;
                    pc[j] = 1;
                }
                else{
                    pc[j] = 0;
                }
            }
            if(coun >= k){
                ans += (1<<i);
                check = pc;
            }
            pc.clear();
            pc.resize(n);
        }
    }
    cout <<ans <<"\n";
}
signed main(){
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    ll tc = 1;
    //cin >>tc;
    while(tc--){
        solve();
    }
}
