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

inline void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int l = 0, r = 1e15;
	while(r - l > 1) {
		int m = l + (r - l) / 2;
		int cnt = 0;
		int brr = 0;
		for(int i = 0; i < n; i++) {
			brr |= a[i];
			if(brr >= m) {
				brr = 0;
				cnt++;
			}
		}
		
		if(cnt >= k) l = m;
		else r = m;
		
	}
	
	int ans;
	int count = 0;
	int trr= 0;
	int in = 0;
	for(int i = 0; i < n; i++) {
		if(count == k - 1) break;
		trr |= a[i];
		if(trr >= l && count < k - 1) {
			if(count == 0) ans = trr;
			else {
				ans &= trr;
			}
			trr = 0;
			in = i + 1;
			count++;
		}
	}
	trr = 0;
	for(int i = in; i < n; i++) {
		trr |= a[i];
	}
	cout << (ans & trr) << '\n';
	
}

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












