#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;

void getBiggestBit()
{
    vector<int> special;
    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;
        }
    }

    int ptr=0, currOr=0;
    vector<int> newA;

    if(special.empty())
    {
        currBit=-1;
        return;
    }

    for(int i=0; i<a.size(); i++)
    {
        if(i<special[0])
        {
            currOr|=a[i];
        }
        else if(i>=special.back())
        {
            currOr|=a[i];
        }
        else
        {
            if(currOr==0)
            {
                newA.push_back(a[i]);
            }
            else
            {
                newA.push_back(currOr|a[i]);
                currOr=0;
            }
        }
    }
    newA.push_back(currOr);

    a=move(newA);
    currBit=bit;
    if(currBit>=0)
    {
        ans|=(1<<currBit);
    }
    ///cout<<a.size()<<'\n';
}

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

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

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

    while(currBit>0)
    {
        getBiggestBit();
        ///cout<<currBit<<'\n';
    }

//    cout<<a.size()<<'\n';
//    for(auto x: a)
//    {
//        cout<<x<<' ';
//    }
//    cout<<'\n';
    cout<<ans<<'\n';
    return 0;
}
