#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main(){
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    ll n,k;
    cin >>n >>k;
    vector<ll> cnt(30), ok;
    ll ans = 0;
    vector< vector<ll> > v(30,vector<ll>(n));
    for(ll i = 0 ; i < n; i++){
        ll x;
        cin >>x;
        for(ll j = 0; j < 30; j++){
            v[j][i] = ((x>>j)&1);
            cnt[j] += v[j][i];
        }
    }
    for(ll i = 29; i >= 0; i--){
        if(cnt[i] >= k){
            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){
                ok.push_back(i);
                ans |= (1<<i);
            }
        }
    }
    cout <<ans <<"\n";
}
