#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;
    if(n <= 100000){
        vector<ll> v(n),cnt(30), ok;
        ll ans = 0;
        for(ll i = 0 ; i < n; i++){
            cin >>v[i];
            for(ll j = 0; j < 30; j++){
                cnt[j] += ((v[i]>>j)&1);
            }
        }
        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[j]>>ok[x])&1)){
                            hmm = (hmm|(1<<x));
                        }
                    }
                    if(((v[j]>>i)&1)){
                        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";
        return 0;
    }
    vector<ll> v(n),cnt(30), pc(n,1), check(n);
    ll ans = 0;
    ll arlan = 0;
    for(ll i = 0 ; i < n; i++){
        cin >>v[i];
        for(ll j = 0; j < 30; j++){
            cnt[j] += ((v[i]>>j)&1);
        }
    }
    for(ll i = 29; i >= 0; i--){
        if(cnt[i] >= k){
            ll coun = 0, hmm = 0;
            if(arlan == 0){
                for(ll j = 0; j < n; j++){
                    pc[j] = ((v[j]>>i)&1);
                }
                arlan++;
                ans |= (1<<i);
                continue;
            }
            for(ll j = 0; j < n; j++){
                check[j] = pc[j];
                check[j] |= (((v[j]>>i)&1)<<arlan);
                hmm |= check[j];
                if(hmm == (1<<(arlan+1))-1){
                    hmm = 0;
                    coun++;
                    if(coun >= k){
                        break;
                    }
                }
            }
            if(coun >= k){
                arlan++;
                ans |= (1<<i);
                pc = check;
            }
        }
    }
    cout <<ans <<"\n";
}
