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

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

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

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