#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
struct Trie {
int child_num;
Trie* next[2];
Trie() {
child_num = 0;
for (int i = 0; i < 2; i++) next[i] = NULL;
}
~Trie() {
for (int i = 0; i < 2; i++) {
if (next[i]) delete next[i];
}
}
void Insert(const char* s) {
child_num++;
if (!*s) return;
int now = *s - '0';
if (!next[now]) next[now] = new Trie;
next[now]->Insert(s + 1);
}
};
ll n, k;
ll a[101010];
string s[101010];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
for (int j = 30; j >= 0; j--) {
if (a[i] & (1 << j)) s[i] += '1';
else s[i] += '0';
}
}
ll l = -1; ll r = INT_MAX;
while (l + 1 < r) {
ll m = (l + r) >> 1;
Trie* trie = new Trie;
ll cnt = 0;
for (int i = 1; i <= n; i++) {
Trie* ptr = trie;
ll tmp = m;
for (int j = 30; j >= 0; j--) {
int now = s[i][30-j] - '0';
if (tmp >= (1 << j)) {
if (ptr->next[now]) cnt += ptr->next[now]->child_num;
now ^= 1;
tmp ^= (1 << j);
}
if (!ptr->next[now]) break;
ptr = ptr->next[now];
}
trie->Insert(s[i].c_str());
}
delete trie;
if (cnt < k) l = m;
else r = m;
}
cout << r - 1 << '\n';
return 0;
}