#include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = (int)1e6 + 9;

int n, k, a[N];

void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];

    int ans = 0, st = 0;

    for (int i = 30; i >= 0; i--) {
        int kol = 0, nd = 0, tans = ans + (1 << i);

        for (int j = 1; j <= n; j++) {
            nd |= a[j];
            if ((nd & tans) == tans) nd = 0, kol++;
        }

        if (kol >= k) ans += (1 << i);
    }

    cout << ans;
}

main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int qq = 1;
    while (qq--) {
        solve();
        cout << "\n";
    }
}
