#include using namespace std; using ll = long long; template struct BinaryTrie { struct Node { long long cnt = 0; int ch[2] = {-1, -1}; }; std::vector ns; BinaryTrie() : ns(1) {} long long size() const { return ns[0].cnt; } long long operator[](int k) const { return find_kth(k, 0); } long long find_kth(long long k, long long xor_add = 0) const { assert(0 <= k && k < size()); long long idx = 0, val = 0; for(int i=LOG-1; i>=0; i--) { long long c = xor_add >> i & 1; long long low_ch = ns[idx].ch[c]; long long low_cnt = (low_ch >= 0 ? ns[low_ch].cnt : 0); if (k < low_cnt) { idx = low_ch; } else { k -= low_cnt; idx = ns[idx].ch[c ^ 1]; val ^= 1LL << i; } assert(idx >= 0); } return val; } void add(long long val, long long cnt = 1) { assert(0 <= val && val < (1LL << LOG)); int idx = 0; for(int i=LOG-1; i>=0; i--) { ns[idx].cnt += cnt; assert(ns[idx].cnt >= 0); int &nxt = ns[idx].ch[val >> i & 1]; if (nxt == -1) { idx = nxt = ns.size(); ns.emplace_back(); } else { idx = nxt; } } ns[idx].cnt += cnt; assert(ns[idx].cnt >= 0); } long long lower_bound(long long val, long long xor_add = 0) { assert(0 <= val); if (val >= (1LL << LOG)) return size(); int idx = 0; long long cnt = 0; for(int i=LOG-1; i>=0; i--) { int b = val >> i & 1, c = xor_add >> i & 1; int ch = ns[idx].ch[c]; cnt += (b & (ch >= 0) ? ns[ch].cnt : 0); idx = ns[idx].ch[b ^ c]; if (idx < 0 or ns[idx].cnt == 0) break; } return cnt; } long long count(long long val) const { assert(0 <= val && val < (1LL << LOG)); int idx = 0; for(int i=LOG-1; i>=0; i--) { idx = ns[idx].ch[val >> i & 1]; if (idx < 0 or ns[idx].cnt == 0) return 0; } return ns[idx].cnt; } long long count(long long L, long long R, long long xor_add = 0) { assert(0 <= L && L <= R && R <= (1LL << LOG)); return lower_bound(R, xor_add) - lower_bound(L, xor_add); } long long xor_min(long long xor_add = 0) { return find_kth(0, xor_add); } long long xor_max(long long xor_add = 0) { return find_kth(size() - 1, xor_add); } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; vector a(n); BinaryTrie<30> trie; for(auto &&v : a){ cin >> v; trie.add(v); } int ng = -1, ok = 1 << 30; while(ng + 1 < ok){ int mid = (ok + ng) / 2; ll tot = -n; for(auto &&v : a) tot += trie.lower_bound(mid + 1, v); tot /= 2; (tot >= k ? ok : ng) = mid; } cout << ok << '\n'; }