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

#define ll long long

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

    vector<ll> arr(n, 0);
    vector<vector<ll>> dp(n, vector<ll>(k+1, 0));

    for(ll i = 0; i<n; i++) cin>>arr[i];


    dp[0][1] = arr[0];
    for(ll i = 1; i<n; i++) dp[i][1] = (dp[i-1][1] | arr[i]);

    for(ll i = 2; i<=k; i++){
        for(ll curr = 0; curr<n; curr++){
            ll o = arr[curr];
            for(ll j = curr-1; j>=0; j--){
                dp[curr][i] = max(dp[curr][i], (o & dp[j][i-1]));
                o = o|arr[j];
            }
        }
    }

    cout<<dp[n-1][k]<<endl;
    return 0;
}