#include <bits/stdc++.h>

using namespace std;

int a[1000005];

int main()
{
    //freopen("input.txt","r",stdin);
    int n,k;
    cin >> n >> k;
    int Max = 0;
    for (int i=0;i<n;++i){
        cin >> a[i];
        Max = max(Max,a[i]);
    }
    if (n<=20){
        int m = n;
        int ans = 0;
        for (int msk=0;msk<(1<<m);++msk){
            if (msk&1) continue;
            vector <int> v;
            v.push_back(0);
            for (int bit=0;bit<m;++bit){
                if (msk&(1<<bit)) v.push_back(bit);
            }
            v.push_back(n);
            if (v.size()!=k+1) continue;
            int loc = -1;
            for (int i=0;i+1<v.size();++i){
                int val = 0;
                for (int j=v[i];j<v[i+1];++j) val |= a[j];
                if (loc==-1) loc = val;
                else loc &= val;
            }
            ans = max(ans,loc);
        }
        cout << ans;
        return 0;
    }
    if (Max==1){
        int fr1 = 0;
        for (int i=0;i<n;++i) fr1 += a[i];
        if (fr1>=k) cout << 1;
        else cout << 0;
        return 0;
    }
    assert(0);
    return 0;
}
