#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	int N;cin>>N;
	int K;cin>>K;K--;

	vector<int> A(N);for(auto&&e:A)cin>>e;

	int S=0;

	for(int i=30;i>=0;i--){
		unordered_map<int,int> mp;

		for(auto&&e:A){
			mp[(e>>i)<<i]++;
		}

		int cnt=0;

		for(auto&&[e,c]:mp){
			if(e>(e^S))continue;
			if(S==0){
				cnt+=c*(c-1)/2;
			}else{
				if(mp.count(e^S)){
					cnt+=c*mp[e^S];
				}
			}
		}

		if(cnt<=K){
			S|=1<<i;
			K-=cnt;
		}

	}

	cout<<S<<endl;
}