#include<iostream>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
const int N=1e6+5,BITS=32;
int aS[N];
int br[BITS];
vector<int> bitsInRed[N];
int n,k;
vector<int> bitsOfNumber(int e)
{
    vector<int> bits;
    int i=0;
    while(e>0)
    {
        if(e&1)bits.push_back(i);
        ++i;
        e>>=1;
    }
    return bits;
}
inline bool groups(const set<int>& vazhniBitove)
{
    int i=0,groups=0;
    set<int> popilneni;
    while(i<n)
    {
        while(i<n)
        {
            if(popilneni.size()==vazhniBitove.size())break;
            for(auto b:bitsInRed[i])
                if(vazhniBitove.find(b)!=vazhniBitove.end())
                popilneni.insert(b);
            ++i;
        }
        if(popilneni.size()!=vazhniBitove.size())break;
        cerr<<i<<" "<<popilneni.size() <<endl;
        popilneni.clear();
        ++groups;
        if(groups>=k)return 1;
    }
    return groups>=k;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    cin>>n>>k;
    for(int i=0; i<n; ++i)cin>>aS[i];
    for(int i=0; i<n; ++i)bitsInRed[i]=bitsOfNumber(aS[i]);
    for(int i=0; i<n; ++i){
        for(auto b:bitsInRed[i])
            ++br[b];
    }
    int out=0,bitF=BITS-1;
    while(bitF>=0&&br[bitF]<k)--bitF;
    if(bitF==-1){
        cout<<"0\n";return 0;
    }
    set<int> vazhniBits;
    vazhniBits.insert(bitF);
    //cerr<<bitF<<endl;

    for(int bitNow=bitF;bitNow>=0;--bitNow)
    {
        vazhniBits.insert(bitNow);
        if(groups(vazhniBits)){out|=(1<<bitNow);}
        else vazhniBits.erase(bitNow);
    }

    cout<<out<<"\n";
}
