#include <iostream>
const int NMAX=305;

using namespace std;

int v[NMAX];
int maxi=0,n,k;

void bkt(int pos,int partitie,int k,int ans,int orPar)
{
    if(pos==n+1 && partitie==k)
    {
        maxi=max(maxi,ans&orPar);
        ///cout<<ans<<endl;
    }
    else if(pos<=n && partitie<=k)
    {
        bkt(pos+1,partitie+1,k,int(ans&orPar),v[pos]); ///cream partitie
        bkt(pos+1,partitie,k,ans,int(orPar|v[pos])); ///nu cream partitie
    }
}

signed main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    bkt(1,0,k,2147483647,2147483647);
    cout<<maxi<<endl;
    return 0;
}

/*7 3
2 1 4 3 2 2 5*/
