#include <iostream>
#include <vector>
using namespace std;

#define ll long long

vector<ll> arr;
vector<vector<ll>> dp;

ll find(ll indx, ll k){
    if(dp[indx][k] != -1) return dp[indx][k];
    if(k == 1){
        ll ans = 0;
        for(ll i = 0; i<=indx; i++) ans = (ans|arr[i]);
        return dp[indx][k] = ans;
    }

    ll best = 0;
    ll o = arr[indx];
    for(ll i = indx-1; i>=k-2; i--){
        best = max(best, ((find(i, k-1)) & o));
        o = (o|arr[i]);
    }

    return dp[indx][k] = best;
}

int main(void){
    // freopen("input.txt", "r", stdin);
    ll n, k;
    cin>>n>>k;

    arr.assign(n, 0);
    dp.assign(n, vector<ll>(k+1, -1));
    for(ll i = 0; i<n; i++) cin>>arr[i];
    cout<<find(n-1, k)<<endl;
    return 0;
}