#include <bits/stdc++.h>
#define int long long 
#define pb push_back
using namespace std;

struct sg {
	vector<int> t;
	sg(int n){
		t.assign(n * 4, 0);
	}
	
	void set(int v, int l, int r, int pos, int val) {
		if(l == r) {
			t[v] = val;
			return;
		}
		int m = l + (r - l) / 2;
		if(pos <= m) set(2 * v, l, m, pos, val);
		else set(2 * v + 1, m + 1, r, pos, val);
		t[v] = (t[v * 2] | t[v * 2 + 1]);
	}
	int get(int v, int l, int r, int ql, int qr) {
		if(ql > r || l > qr) return 0;
		if(ql <= l && qr >= r) return t[v];
		int m = l + (r - l) / 2;
		return (get(2 * v, l, m, ql, qr) | (get(2 * v + 1, m + 1, r, ql, qr)));
	}
};

inline void ssolve() {
	int n, k; cin >> n >> k;
	sg st(n);
	for(int i = 0; i < n; i++) {
		int x; cin >> x;
		st.set(1, 0, n - 1, i, x);
	}
	int tot = 0;
	for(int mask = 0; mask <= (1 << n); mask++) {
		int cnt = 0;
		vector<int> brr;
		bool can = true;
		for(int i = 0; i < n; i++) {
			if(mask & (1 << i)) {
				cnt++;
				brr.pb(i);
			}
		}
		if(cnt != k || brr.back() != n - 1) continue;
		int l = 0;
		int ans = -1;
		for(int i = 0; i < brr.size(); i++) {
			int x = st.get(1, 0, n - 1, l, brr[i]);
			l = brr[i] + 1;
			if(ans == -1) ans = x;
			else ans &= x;
		}
		tot = max(tot, ans);
	}
	cout << tot << '\n';
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ssolve();
}