#include <bits/stdc++.h>
using namespace std;
int cntbytes(int n) {
    int pn = n, cnt = 0;
    while (n > 0) {
        n >>= 1;
        cnt += pn - n << 1;
    }
    return cnt;
}
int main() {
    ios :: sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> a(n), cntby(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cntby[i] = cntbytes(a[i]);
    }
    while (a.size() > k) {
        int pos = 0;
        int cntb = 0;
        for (int i = 0; i < a.size() - 1; i++) {
            int b = 2 * cntbytes(a[i] | a[i + 1]) - cntby[i] - cntby[i + 1];
            if (b > cntb) {
                pos = i;
                cntb = b;
            }
        }
        a[pos] = a[pos] | a[pos + 1];
        cntby[pos] = (cntb + cntby[pos] + cntby[pos + 1]) / 2;
        a.erase(a.begin() + pos + 1);
    }
    int calc = a[0];
    for (int i = 1; i < k; i++) {
        calc = calc & a[i];
    }
    cout << calc;
}
