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

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

int qur(int l, int r){
    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));
        }
    }
}

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


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))]);
        }
    }
    for(int i = 0; i < n; i++) {
        rec(i+1, qur(0, i), k-1);
    }
    cout << ansG << endl;

    
}