#include <bits/stdc++.h>
using namespace std;
long long  n,k;
long long  a[1000005];
bool o[2001][1000];
bool check(long long  mid)
{
    long long  curr=0;
    long long  groups=0;
    long long  buf=mid;
    vector<long long >ones;
    long long  c=0;
    while((1<<c)<=buf)
    {
        if((1<<c) & buf)
        {
            //cout<<c<<" ";
            ones.push_back(c);
        }
        c++;
    }
    //cout<<endl;
    for(long long  i=0; i<n; i++)
    {
        bool tr=1;
        for(auto t:ones)
        {
            if(!((1<<t) & curr))
            {
                tr=0;
                break;
            }
        }
        if(tr==1)
        {
            groups++;
            curr=0;
        }
        curr|=a[i];
    }
    if(curr>=mid)groups++;
    //cout<<"GROUPS "<<groups<<" "<<mid<<endl;
    if(groups>=k)
    {
        //cout<<1<<endl;
        return true;
    }
    else return false;
}
int  main()
{
    cin>>n>>k;
    long long  MAX=0;
    for(long long  i=0; i<n; i++)
    {
        cin>>a[i];
        MAX|=a[i];
        //cout<<MAX;
    }
    long long  maxc=0;
    for(long long  c=0; (1<<c)<=MAX; c++)
    {
        if(MAX&(1<<c))
        {
            maxc=c;
        }
    }

    long long  mask=0;
    //long long  maxx=0;
    for(long long  i=maxc+1; i>=0; i--)
    {
        //cout<<"I "<<i<<endl;
        mask=mask | (1<<i);
        if(!check(mask))
        {
            mask^=(1<<i);
        }
        //cout<<"end "<<(1<<i)<<" "<<mask<<endl;
    }
    cout<<mask;


}
