#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair <ll,ll>;
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define pb push_back
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin >> n >> k;
	ll p = 0;
	vector <ll> v(n + 1);
	for (ll i = 1;i <= n;i++){
		cin >> v[i];
		p = max(p,__lg(v[i]));
	}
	vector<vector <bool>> t(p + 1,vector <bool>(n + 1));
	for (ll i = p;i >= 0;i--){
		for (ll j = 1;j <= n;j++){
			t[i][j] = bool((v[j] >> i) & 1);
		}
	}
	ll ans = 0;
	for (ll i = p;i >= 0;i--){
		ll cnt = 0;
		ll cnt2 = 0;
		ans = ans | (1 << i);
		for (ll j = 1;j <= n;j++){
			cnt = cnt | v[j];
			bool b = true;
			for (ll l = p;l >= i;l--){
				if (ans & (1 << l)){
					if (!(cnt & (1 << l))){
						b = false;
					}
				}
			}
			if (b){
				cnt = 0;
				cnt2++;	
			}
		}
		if (cnt2 < k)ans ^= (1 << i);
	}
	cout << ans <<"\n";
}