#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(32), ok;
    ll ans = 0;
    vector< vector<ll> > v(32,vector<ll>(n));
    for(ll i = 0 ; i < n; i++){
        ll x;
        cin >>x;
        for(ll j = 0; j < 32; j++){
            v[j][i] = ((x>>j)&1);
            cnt[j] += v[j][i];
        }
    }
    for(ll i = 31; i >= 0; i--){
        if(cnt[i] >= k){
            bool sigma = 1;
            ll coun = 0, hmm = 0;
            for(ll j = 0; j < n; j++){
                for(ll x = 0; x < ok.size();x++){
                    if(v[ok[x]][j]){
                        hmm = (hmm|(1<<x));
                    }
                }
                if(v[i][j]){
                    hmm = (hmm|(1<<(ok.size())));
                }
                if(hmm == (1<<(ok.size()+1))-1){
                    hmm = 0;
                    coun++;
                    if(coun == k){
                        break;
                    }
                }
            }
            if(coun < k){
                sigma = 0;
            }
            if(sigma){
                ok.push_back(i);
                ans += (1<<i);
            }
        }
    }
    cout <<ans <<"\n";
}
signed main(){
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    ll tc = 1;
    //cin >>tc;
    while(tc--){
        solve();
    }
}

