#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;

void solve() {
    int k, n;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = B - 1; i >= 0; i--) {
        int cnt = 0;
        int cur = 0;
        int nans = ans | (1 << i);
        for (int j = 0; j < n; j++) {
            cur |= a[j];
            if ((cur & nans) >= nans) {
                cnt++;
                cur = 0;
            }
        }
        if (cnt >= k) {
            ans = nans;
        }
    }
    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;
}
