#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 t=mid;
    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++;
            //cout<<i<<" "<<groups<<endl;
            curr=0;
        }
        curr|=a[i];
        //cout<<"CURR "<<curr<<endl;
    }
    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 mask=0;
    int maxx=0;
    for(int i=MAX;i>=0;i--)
    {
        if(check(i)==1)
        {
            cout<<i;
            return 0;
        }

    }


}
