#include <bits/stdc++.h>
using namespace std;
#define vc vector
#define vi vc<int>
#define int long long

signed main() {
    cin.tie(0)->ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vi a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    vc<vi>t(n, vi(n));
    for(int i = 0; i < n; i++){
        for(int j = i; j < n; j++){
            if(i == j)t[i][j] = (a[i] | a[j]);
            else {
                t[i][j] = (t[i][j - 1] | a[j]);
            }
        }
    }
    //for(int i = 0; i < n; i++){
    //    for(int j = 0; j < n; j++){
    //        cout << t[i][j] << ' ';
    //    }
    //    cout << '\n';
    //}
    int ans;
    int l = 0;
    int ok = k;
    while(k > 0){
        int mx = -1e9, mxind = -1, mxl = -1;
        for(int r = l; r < n - k + 1; r++){
            int old = mx;
            mx = max(mx, t[l][r]);
            if(mx != old){
                mxind = r;
                mxl = l;
            }
        }
        if(k == ok)ans = mx;
        else ans &= mx;
        l = mxind + 1;
        //cout << mxl << ' ' << mxind << ' ' << mx << '\n';
        k--;
    }
    cout << ans << '\n';
}
