#include <iostream>
using namespace std;

int v[1000000], r = 0;

void f(int n, int k, int i = 0, int t = 0x3fffffff){
    int p = 0;
    for (; i <= n - k; i++){
        p |= v[i];
        if (k > 1 && (t & p) >= r) f(n, k-1, i+1, t & p);
    }
    if (k == 1) r = max(r, t & p);
}

int main(){
    int n, k;
    cin  >> n >> k;

    for (int i = 0; i < n; i++) cin >> v[i];

    f(n, k);
    cout << r;

    return 0;
}
