#include <bits/stdc++.h>
#define int signed
using namespace std;

const int MAXN=1e6, MAXK=MAXN;
int n, k;
vector<int> a;
int currBit=31;
int ans=0;
vector<int> special;

void getBiggestBit()
{
    int bit=-1;
    for(int b=currBit-1; b>=0; b--)
    {
        special.clear();
        for(int i=0; i<a.size(); i++)
        {
            if((a[i]&(1<<b))!=0)
            {
                special.push_back(i);
            }
        }
        if(special.size()>=k)
        {
            bit=b;
            break;
        }
    }

    currBit=bit;
    ans|=(1<<currBit);
}

int main()
{
    cin>>n>>k;

    a.resize(n+1);
    bool allZeroes=true;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(a[i]!=0) allZeroes=false;
    }

    if(k==1)
    {
        int currOr=0;
        for(int i=1; i<=n; i++)
        {
            currOr|=a[i];
        }
        cout<<currOr<<'\n';
        return 0;
    }
    if(allZeroes)
    {
        cout<<"0\n";
        return 0;
    }

    special.push_back(0);
    getBiggestBit();
    for(int b=currBit-1; b<n; b++)
    {
        vector<int> jump(n+1);
        vector<int> val(n+1);
        for(int i=1; i<=n; i++) val[i]=a[i];
        iota(jump.begin(), jump.end(), 1);

        int cnt=0;
        for(int i=1; i<special.size(); i++)
        {
            int curr=special[i], prev=special[i-1];
            int Or=0;
            bool gotOne=false;
            for(int j=curr; j>=jump[prev]; j--)
            {
                Or|=a[j];
                if((a[j]&(1<<b))!=0)
                {
                    jump[j]=curr+1;
                    val[j]=Or;
                    cnt++;
                    gotOne=true;
                    break;
                }
            }

            if(gotOne)
            {
                continue;
            }

            Or=0;
            for(int j=curr; j<a.size(); j++)
            {
                Or|=a[j];
                if((a[j]&(1<<b))!=0)
                {
                    jump[curr]=j+1;
                    val[curr]=Or;
                    cnt++;
                    break;
                }
            }
        }
        if(cnt<k) continue;
        vector<int> newA;
        vector<int> newSpecial={0};
        int curr=1;
        while(curr<n)
        {
            newA.push_back(val[curr]);
            if(jump[curr]!=curr+1)
            {
                newSpecial.push_back(newA.size());
            }
            curr=jump[curr];
        }
        a=move(newA);
        special=move(newSpecial);
        ans|=(1<<b);
    }
    cout<<ans<<'\n';
    return 0;
}
