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

#define ll long long

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

void find(ll indx, ll k){
    dp[indx][k].assign(2050, 0);

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

    ll best = 0;
    ll o = arr[indx];
    for(ll i = indx-1; i>=k-2; i--){
        for(int j = 0; j<2050; j++){
            if(dp[i][k-1][j]) dp[indx][k][(j&o)] = 1;
        }
        o = o|arr[i];
    }

    return;
}

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

    arr.assign(n, 0);
    dp.assign(n, {});

    for(int i = 0; i<n; i++) dp[i].assign(k+1, {});

    for(ll i = 0; i<n; i++) cin>>arr[i];
    for(int i = 0; i<n; i++){
        for(int j = 1; j<=min(k, i+1); j++) find(i, j);
    }

    int mx = 0;
    for(int i = 0; i<2050; i++) if(dp[n-1][k][i]) mx = i;

    cout<<mx<<endl;
    return 0;
}

