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

const int MAXL = 31;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k; cin >> n >> k;
    int ans = 0;
    vector <int> a(n);
    int mx = 0;
    for (auto &x : a) {
        cin >> x;
        mx |= x;
    }
    for (int bit1 = MAXL; bit1 >= 0; bit1--) {
        int num = (ans | (1LL << bit1));
        if (num > mx) continue;
        int cur = 0;
        int br = 0;
        for (int i = 0; i < n; i++) {
            cur |= a[i];
            bool f = true;
            if (((cur | num) ^ cur) == 0) {
                ///cout << cur << endl;
                cur = 0;
                br++;
                if (br == k) break;
                ///cout << num << " " << i << endl;
            }
        }
        if (br >= k) {
            ans = num;
        }
    }
    cout << ans << endl;
}
