#include<bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> v;
map<pair<ll,ll>, ll> m;
ll tree[4*300000];
void buildtree(ll ind, ll l, ll r){
    if(l==r){
        tree[ind]=v[l];
        return;
    }
    ll mid=(l+r)/2;
    buildtree(2*ind, l, mid);
    buildtree(2*ind+1, mid+1, r);
    tree[ind]=tree[2*ind]&tree[2*ind+1];
}
ll interval(ll ind,ll l,ll r,ll ql, ll qr){
    if(l==r){
        return tree[ind];
    }
    ll mid =(l+r)/2;
    ll ans=0;
    if(ql<=mid){
        ans|=interval(2*ind,l,mid,ql,qr);
    }
    if(qr>mid){
        ans|=interval(2*ind+1,mid+1,r,ql,qr);
    }
    return ans;
}
ll bigger(ll ok){
    ll i=2;
    while(i<ok){
        //cout<<67;
        //i*=2;
        i=i<<1;
    }
    return i;
}
ll maxansi=0;
ll n;
void all(ll k, ll start, ll ok){
    if(k==1){
        if(m.find({start,n-1})==m.end()){
            m[{start,n-1}]=interval(1,0,n-1,start,n-1);
        }
        if(ok==-1){
            ok=(m[{start,n-1}]);
        }
        else{
            ok&=(m[{start,n-1}]);
        }
        if(ok>maxansi){
            maxansi=ok;
        }
        return;
    }
    for(ll i=start; i<v.size()-(k-1); i++){
        ll ko=ok;
        if(m.find({start,i})==m.end()){
            m[{start,i}]=interval(1,0,n-1,start,i);
        }
        if(ko==-1){
            ko=m[{start,i}];
        }
        else{
            ko&=m[{start,i}];
        }
        if(bigger(ko)<=maxansi){
            return;
        }
        all(k-1,i+1,ko);
    }
    return;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll k;
    cin>>n>>k;
    ll ai;
    for(ll i=0; i<n; i++){
        cin>>ai;
        v.push_back(ai);
    }
    //cout<<bigger(128)<<endl;
    buildtree(1,0,n-1);
    all(k,0,-1);
    cout<<maxansi;
}
