#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ls(v) (int)v.size()
#define pb push_back
#define wr cout << "------------------------------" << endl
signed main(){
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("file.in", "r", stdin);
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 1);
    for(int i = 1;i<=n;++i){
        cin >> a[i];
    }
    ll ans = 0;
    int cnt = 0;
    set<int> st;
    for(int j = 29;~j;--j){
        st.insert(j);
        set<int>s;
        int res = 0;
        for(int i = 1;i<=n;++i){
            for(int j = 0;j<30;++j){
                if(a[i] >> j & 1 and st.count(j)) s.insert(j);
            }
            if(ls(s) == ls(st)){
                res += 1;
                s.clear();
            }
        }     
        if(res < k) st.erase(j);
    }
    for(auto it:st) ans += (1 << it);
    cout << ans << endl;
}