#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second

const int B = 31;
const int N = 1e6 + 67;
vector<int> hv_b[B];
int pr_b[B][N];

void solve() {
    int k, n;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < B; i++) {
        for (int j = 0; j < n; j++) {
            int bt = a[j] >> i & 1;
            pr_b[i][j + 1] = pr_b[i][j] + bt;
            if (bt) {
                hv_b[i].pb(j);
            }
        }
    }
    int ans = 0;
    for (int i = B - 1; i >= 0; i--) {
        if (sz(hv_b[i]) < k) {
            continue;
        }
        ans += (1 << i);
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
