#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[1000005];

bool check(int mid)
{
    int curr=0;
    int groups=0;
    int buf=mid;
    vector<int>ones;
    int c=0;
    while((1<<c)<=buf)
    {
        if((1<<c) & buf)
        {
            //cout<<c<<" ";
            ones.push_back(c);
        }
        c++;
    }
    //cout<<endl;
    for(int 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;
    int MAX=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        MAX|=a[i];
        //cout<<MAX;
    }
    int l=0;
    int r=MAX+1;
    while(l<r-1)
    {
        //cout<<l<<" "<<r<<endl;
        int mid=(l+r)/2;
        if(check(mid)==1)
        {
            l=mid;
        }
        else
        {
            r=mid;
        }
    }
    cout<<l;


}
