#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);
    int mx = 0;
    for (auto &x : a) {
        cin >> x;
        mx |= x;
    }
    for (int num = mx; num >= 1; num--) {
        int cur = 0;
        int br = 0;
        for (int i = 0; i < n; i++) {
            cur |= a[i];
            bool f = true;
            for (int bit = 0; (1 << bit) <= num; bit++) {
                ///cout << ((num >> bit) & 1) << " " << ((cur >> bit) & 1) << endl;
                if ((1 << bit) & num) {
                    if (!((1 << bit) & cur)) {
                        f = false;
                    }
                }
            }
            if (f) {
                ///cout << cur << endl;
                cur = 0;
                br++;
                ///cout << num << " " << i << endl;
            }
        }
        if (br >= k) {
            cout << num << endl;
            return 0;
        }
    }
}
