#include "bits/stdc++.h"
using namespace std;
#define ll long long
const ll N = 2005;
ll a[N];
ll dp[N][N];
signed main(){
    // freopen("file.in", "r", stdin);
    ll n, k;
    cin >> n >> k;
    for(ll i = 1;i<=n;++i) cin >> a[i];
    dp[1][1] = a[1];
    dp[0][0] = (1 << 20) - 1;
    for(ll i = 2;i<=n;++i){
        for(ll j = 1;j<=k;++j){
            ll x = a[i];
            for(ll p = i - 1;~p;--p){
                dp[i][j] = max(dp[i][j], dp[p][j - 1] & x);
                x |= a[p];
            }
        }
    }
    assert(dp[n][k] > 0);
    cout << dp[n][k] << endl;
}