#include <iostream>
using namespace std;

int t[2048], l[2048];

int main(){
    int n, k, num, mn = 0;
    cin  >> n >> k;

    for (int i = 0; i < n; i++){
        cin >> num;
        for (int j = mn+1; j < 2048; j++){
            l[j] |= num;
            if ((l[j] & j) == j) l[j] = 0, t[j]++;
            if (t[j] >= k) mn = j;
        }
    }

    cout << mn;

    return 0;
}
