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

const int MAXL = 31;

int main() {
    int n, k; cin >> n >> k;
    int ans = 0;
    vector <int> a(n);
    for (auto &x : a) cin >> x;
    vector <int> v[MAXL + 5];
    vector <int> p[MAXL + 5];
    for (int bit = MAXL; bit >= 0; bit--){
        for (int i = 0; i < n; i++) {
            if (a[i] & (1 << bit))  {
                v[bit].push_back(i);
                if (p[bit].size() < k) p[bit].push_back(i + 1);
            }
        }
        if (v[bit].size() < k){
            p[bit].clear();
            continue;
        }
        /**
        for (int i = MAXL; i >= bit; i--) {
            if (p[i].size()) {
                cout << i << ": ";
                for (auto x : p[i]) cout << x << " ";
                cout << endl;
            }
        }*/
        int lst = 0;
        vector <int> tmp[MAXL + 5];
        for (int i = MAXL; i >= bit; i--) {
            tmp[i] = p[i];
        }
        bool f = true;
        for (int i = 0; i < k; i++) {
            int nw = 0;
            if (!f) break;
            for (int cur = MAXL; cur >= bit; cur--) {
                int x = 0;
                if (p[cur].size() == 0) continue;
                while (p[cur][i] <= lst && x < v[cur].size()) {
                    ///cout << i << " " << cur << " " << lst << " " << x << " " << v[cur][x] << endl;
                    p[cur][i] = v[cur][x++] + 1;
                }
                if (p[cur][i] <= lst) f = false;
                nw = max(nw, p[cur][i]);
            }
            lst = nw;
        }
        if (f) {
            ans += (1 << bit);
            ///for (auto x : p[bit]) cout << x << " ";
            ///cout << endl;
        }
        else {
            for (int i = MAXL; i >= bit; i--) {
                p[i] = tmp[i];
            }
        }
    }
    cout << ans << endl;
}

