#pragma optimize("Ofast,avx")
#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;
inline 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;
}
bool vazhniBits[BITS];
bool popilneni[BITS];
inline bool groups(const int &needed)
{
    int i=0,groups=0,popilneniBr=0;
    while(i<n)
    {
        while(i<n)
        {
            if(popilneniBr==needed)break;
            for(auto b:bitsInRed[i])
                if(vazhniBits[b] &&!popilneni[b])
                popilneni[b]=1,popilneniBr++;
            ++i;
        }
        memset(popilneni,0,sizeof(popilneni));
        if(popilneniBr!=needed)break;
        //cerr<<i<<" "<<popilneni.size() <<endl;
        popilneniBr=0;
        ++groups;
        if(groups>=k)return 1;
    }
    return groups>=k;
}
int main()
{
    const auto start{std::chrono::steady_clock::now()};
    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;
    }
    //cerr<<bitF<<endl;
    int needed=0;
    for(int bitNow=bitF;bitNow>=0;--bitNow)
    {
        vazhniBits[(bitNow)]=1,++needed;
        if(groups(needed)){out|=(1<<bitNow);}
        else vazhniBits[bitNow]=0,--needed;
    auto end2{std::chrono::steady_clock::now()};
    std::chrono::duration<double> elapsed_seconds{end2 - start};
    if(elapsed_seconds>=0.39){
    cout<<out<<"\n";
        return 0;
    }
    }
    cout<<out<<"\n";
}
