#include<bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MAX_N = 1e6;
int n, k, a[MAX_N];
int ans;

void rec(int currpos, vector<int> c) {
    if(c.size() == k - 1) {
        //for(auto ci : c) cout << ci << " "; cout << " : ";
        int y = 0;
        for(int i = 0; i <= c[0] - 1; ++i) {
            y |= a[i];
        }
        //cout << y << ", ";
        int curans = y;
        for(int i = 1; i < c.size(); ++i) {
            int x = 0;
            for(int j = c[i - 1]; j <= c[i] - 1; ++j) {
                x |= a[j];
            }
            curans &= x;
        }
        y = 0;
        for(int i = c.back(); i < n; ++i) {
            y |= a[i];
        }
        //cout << y << ",  ";
        curans &= y;
        //cout << curans << endl;
        ans = max(ans, curans);
        return;
    }
    for(int i = currpos + 1; i < n; ++i) {
        c.push_back(i);
        rec(i, c);
        c.pop_back();
    }
}

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

    cin >> n >> k;
    int cnt1 = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];

    }

    rec(-1, {});
    cout << ans << endl;

    return 0;
}
