#include <bits/stdc++.h>
#include <numeric>

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;



ll leafNum(ll leafN){
    ll res = 1;
    while(res < leafN)  res *= 2;
    return res;
}

vector<ll> segmentTree(ll leafN){
    return vector<ll>(2 * leafN, 0);
}

ll parent(ll x){
    return (x-1)/2;
}
vector<ll> child(ll x){
    vector<ll> res(2, 0);
    res[0] = 2*x + 1;
    res[1] = 2*x + 2;
    return res;
}

ll comp(ll x, ll y){
    return x + y;
}

//  n is 2^N, equal num of leaf
void update(vector<ll>& segTree, ll leafN, ll index, ll value){
    index += leafN - 1;
    segTree[index] = value;
    while(0 < index){
        index = parent(index);
        vector<ll> childs = child(index);
        ll up = comp(segTree[childs[0]], segTree[childs[1]]);
        if(segTree[index] == up)    index = 0;
        else                        segTree[index] = up;
    }
}

//  [l, r)
ll query(vector<ll>& segTree, ll l, ll r, ll nodeId, ll nodeL, ll nodeR){
    ll EMP = 0; //  will change
    if(nodeR <= l || r <= nodeL)    return EMP;
    if(l <= nodeL && nodeR <= r){
        return segTree[nodeId];
    }
    vector<ll> childs = child(nodeId);
    ll mid = (nodeL+nodeR)/2;
    ll vl = query(segTree, l, r, childs[0], nodeL, mid);
    ll vr = query(segTree, l, r, childs[1], mid, nodeR);
    return comp(vl, vr);
}

ll up;
ll solve(vector<ll>& a, ll l, ll ln, ll k, ll rem){
    ll maxx = 0;
    ll n = a.size();
    if(ln == 0){
        rep(i, n){
            maxx = max(maxx, solve(a, i, 1, k, a[i]));
        }
        return maxx;
    }

    if(rem == 0) return rem;
    if(rem <= up) return rem;
    if(k <= ln) return rem;
    
    for(ll i = l+1; i < n; i++){
        maxx = max(maxx, solve(a, i, ln+1, k, rem&a[i]));
    }
    return maxx;
}

vector<vector<ll>> makeX(vector<ll> list){
    vector<vector<ll>> ma(45, vector<ll>());
    for(auto x : list){
        ll i = 0;
        ll y = x;
        while(0 < y){
            if(y&1) ma[i].push_back(x);
            i++;
            y = y>>1;
        }
    }
    return ma;
}

vector<ll> rec(vector<vector<ll>> ma, ll k, ll j){
    for(ll i = j-1; 0 <= i; i--){
        if(k <= (ll)ma[i].size()){
            ll u = ma[i][0];
            for(auto x : ma[i]) u = u&x;
            up = u;
            auto mx = makeX(ma[i]);
            auto res = rec(mx, k, i);
            if((ll)res.size() < k) return ma[i];
            return res;
        }
    }
    return vector<ll>();
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    

    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll leafN = leafNum(n);
    vector<ll> segT = segmentTree(leafN);
    rep(i, n) update(segT, leafN, i, a[i]);
   
    vector<ll> st;
    vector<vector<ll>> ma(45, vector<ll>());
    rep(l, n){
        for(ll r = l+1; r <= n; r++){
            ll x = query(segT, l, r, 0, 0, leafN);
            st.push_back(x);
            ll i = 0;
            ll y = x;
            while(0 < y){
                if(y&1) ma[i].push_back(x);
                i++;
                y = y>>1;
            }
        }
    }


    auto list = rec(ma, k, 43);
    if(list.size() == 0) cout << 0 << endl;
    else{
        ll x = list[0];
        for(auto y : list) x = x&y;
        cout << x << endl;
    }

    return 0;
}



Measured memory_bytes: 202624