#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;

int a[maxN];
int n, k;
int ans;

void rec(int i, int val, int j) {
    if(j == k) {
        ans = max(ans, val);
    }
    int cur = 0;
    for(int t = i + 1; t <= n; t++) {
        cur |= a[t];
        if(j == k - 1) {
            if(t == n) {
                rec(t, val & cur, j + 1);
            }
            else continue;
        }
        rec(t, val & cur, j + 1);
    }
}

void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    if(k == 1) {
        int cur = 0;
        for(int i = 1; i <= n; i++)cur |= a[i];
        cout << cur;
        return;
    }
    int cur = 0;
    for(int i = 1; i <= n; i++) {
        cur |= a[i];
        rec(i, cur, 1);
    }
    cout << ans;
}

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

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