#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 = 0; i<n; i++){
        for(ll j = 2; j<=min(i+1, k); j++){
            ll o = arr[i];
            for(ll t = i-1; t>=j-2; t--){
                dp[i][j] = max(dp[i][j], o & dp[t][j-1]);
                o = o|arr[t];
            }
        }
    }

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