#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e6+5,BITS=33;
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 int groups(const vector<int>& vazhniBitove)
{
    int i=0,groups=0;
    bool nam[BITS];
    memset(nam,0,sizeof(nam));
    while(i<n)
    {
        while(i<n)
        {
            int andOfThem=1;
            for(auto e:vazhniBitove)andOfThem&=nam[e];
            if(andOfThem)break;
            for(auto b:bitsInRed[i])
                nam[b]=1;
            ++i;
        }
        int andOfThem=1;
        for(auto e:vazhniBitove)andOfThem&=nam[e];
        if(andOfThem==0)break;
        //cerr<<i<<" "<<andOfThem<<endl;
    memset(nam,0,sizeof(nam));
        ++groups;
    }
    return groups;
}
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;
    }
    vector<int> vazhniBits;
    vazhniBits.push_back(bitF);
    //cerr<<bitF<<endl;

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

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