#include<bits/stdc++.h>
using namespace std;

// #define int long long
#define ll long long
#define pb push_back
#define ff first
#define sc second
#define pii pair<int, int>

const int maxN = 1e6 + 25;
const int inf = 1e9;
const ll big_inf = 1e18;
const int mod = 1e9 + 7;

void solve() {
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int dp[n + 1][k + 1] = {};
    int bit[n + 1][n + 1] = {};
    for(int i = 1; i <= n; i++) {
        int cur = 0;
        for(int j = i; j <= n; j++) {
            cur |= a[j];
            bit[i][j] = cur;
        }
    }
    for(int i = 1; i <= n; i++) {
        dp[i][1] = bit[1][i];
    }
    for(int i = 2; i <= n; i++) {
        for(int j = 2; j <= k; j++) {
            for(int t = i - 1; t >= 1; t--) {
                dp[i][j] = max(dp[i][j], dp[t][j - 1] & bit[t + 1][i]);
            }
        }
    }
    cout << dp[n][k];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    while(t--) {
        solve();
        cout << '\n';
    }
}