//#include #include using namespace std; using lint = long long; constexpr lint mod = 998244353; #define all(x) begin(x), end(x) #define bitcount(n) __builtin_popcountll((lint)(n)) #define fcout cout << fixed << setprecision(15) #define highest(x) (63 - __builtin_clzll(x)) #define rep(i, n) for(int i = 0; i < int(n); i++) #define rep2(i, l, r) for(int i = int(l); i < int(r); i++) #define repr(i, n) for(int i = int(n) - 1; i >= 0; i--) #define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--) constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18; inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; } template void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } } template T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; } template T lcm(T a, T b){ return a / gcd(a, b) * b; } template bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; } template bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; } inline int has(lint i, int j){ return (i >> j) & 1; } int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1}; bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); } struct io_init { io_init() { cin.tie(nullptr); cout.tie(nullptr); std::ios::sync_with_stdio(false); } } io_init; template struct BinaryTrie{ struct Node { Node *child[2]; int under_cnt; Node() : child{nullptr, nullptr}, under_cnt(0) {} }; int B; Node *root; BinaryTrie() : root(new Node()) { if(BIT_COUNT == -1){ B = numeric_limits::digits + int(numeric_limits::is_signed); }else{ B = BIT_COUNT; } } void insert(T x){ Node *at = root; repr(i, B){ (at -> under_cnt)++; bool d = ((x >> i) & 1); if(!(at -> child[d])) (at -> child[d]) = new Node(); at = at -> child[d]; } (at -> under_cnt)++; } int count(T x){ Node *at = root; repr(i, B){ bool d = ((x >> i) & 1); at = at -> child[d]; if(!at) return 0; } return at -> under_cnt; } bool erase(T x){ Node *at = root; repr(i, B){ bool d = ((x >> i) & 1); at = at -> child[d]; if(!at) return false; } at = root; repr(i, B){ (at -> under_cnt)--; bool d = ((x >> i) & 1); at = at -> child[d]; } (at -> under_cnt)--; return true; } int size(){ return root -> under_cnt; } T kth_element(int k){ assert(0 <= k && k < size()); k++; Node *at = root; T ans = 0, one = 1; repr(i, B){ int l_cnt = (at -> child[0] ? at -> child[0] -> under_cnt : 0); if(k <= l_cnt){ at = at -> child[0]; }else{ at = at -> child[1]; k -= l_cnt; ans += (one << i); } } return ans; } }; int main(){ int q, k; cin >> q >> k; k--; BinaryTrie tree; rep(_, q){ int t; cin >> t; if(t == 1){ lint x; cin >> x; tree.insert(x); }else{ if(tree.size() < k + 1){ cout << -1 << endl; }else{ lint ans = tree.kth_element(k); cout << ans << endl; tree.erase(ans); } } } }