#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define pb push_back
const int N = 21;
const int LN = 6;

int n,k;
int a[N];
int st[LN][N];
vi cand;
int ansG = 0;

int qur(int l, int r){
    if(l > r) return 0;
    if(r >= n) return 0;
    int len = r-l+1;
    if(l == r) return a[l];
    for(int i = LN; i >= 0; i--) {
        if(len >= (1 << i)) {
            return (st[i][l] | qur(l+(1 << i)-1, r));
        }
    }
    return 0;
}

void rec(int ind, int cur, int cnt) {
    // cout <<"### REC("<<ind<<", "<<cur<<", " << cnt  << ")" << endl;
    // cout << "# ANS = " << ans << endl;
    // bool last = 0;
    if(ind >= n) return;
    if(cur <= ansG) {
        return;
    }
    if(cnt <= 0) return;
    if(cnt == 1) {
        ansG = max(ansG, (cur & qur(ind, n-1))); return;
    }
    for(int i = ind; i < n; i++) {
        // ind, ind+1, ind+2, ..., i
        int ncur = (cur & qur(ind, i));
        rec(i+1, ncur, cnt-1);
    }
    return;
}


signed main() {
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) st[0][i] = a[i];
    for(int j = 1; j <= LN; j++) {
        for(int i = 0; i + (1 << j) < n; i++) {
            st[j][i] = (st[j-1][i] | st[j-1][i+(1<<(j-1))]);
        }
    }
    if(k == 1) {
        cout << qur(0, n-1) << endl;
        return 0;
    }
    for(int i = 0; i < n; i++) {
        rec(i+1, qur(0, i), k-1);
    }
    cout << ansG << endl;

    return 0;
}