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