#include using namespace std; typedef long long ll; random_device seed_gen; mt19937 engine(seed_gen()); uniform_int_distribution dist_treap(0, (1 << 30) - 1); struct treap { struct node { node *lch, *rch; int par; ll val; int cnt; node(ll v, int p): lch(nullptr), rch(nullptr), par(p), val(v), cnt(1) {} }; int calc_cnt(node* t){ if (t == nullptr) return 0; return t->cnt; } node* update(node* t){ t->cnt = calc_cnt(t->lch) + calc_cnt(t->rch) + 1; return t; } node* merge(node* a, node* b){ if (a == nullptr || b == nullptr){ if (a == nullptr) return b; return a; } if (a->par > b->par){ a->rch = merge(a->rch, b); return update(a); }else{ b->lch = merge(a, b->lch); return update(b); } } pair split(node* t, int k){ if (t == nullptr) return pair(nullptr, nullptr); assert(0 <= k && k <= calc_cnt(t)); if (calc_cnt(t->lch) >= k){ pair ret = split(t->lch, k); t->lch = ret.second; return pair(ret.first, update(t)); }else{ pair ret = split(t->rch, k - calc_cnt(t->lch) - 1); t->rch = ret.first; return pair(update(t), ret.second); } } node* insert(node* t, int k, ll v){ return insert(t, k, v, dist_treap(engine)); } node* insert(node* t, int k, ll v, int p){ pair tar = split(t, k); node* var = new node(v, p); return merge(merge(tar.first, var), tar.second); } node* erase(node* t, int k){ assert(0 <= k && k < calc_cnt(t)); pair spl1 = split(t, k + 1); pair spl2 = split(spl1.first, k); delete spl2.second; return merge(spl2.first, spl1.second); } // returns the number of elements less than v int lower_bound(node* t, ll v){ if (t == nullptr) return 0; if (v <= t->val){ return lower_bound(t->lch, v); }else{ return calc_cnt(t->lch) + 1 + lower_bound(t->rch, v); } } node* insert(node* t, ll v){ return insert(t, lower_bound(t, v), v); } // returns val ll get(node* t, int k){ assert(t != nullptr); if (k < calc_cnt(t->lch)){ return get(t->lch, k); }else if(calc_cnt(t->lch) == k){ return t->val; }else{ return get(t->rch, k - calc_cnt(t->lch) - 1); } } }; int main(){ treap T; treap::node* root = nullptr; int q,k; cin >> q >> k; while(q--){ int t; cin >> t; if (t == 1){ ll v; cin >> v; root = T.insert(root, v); }else{ if (T.calc_cnt(root) >= k){ cout << T.get(root, k-1) << '\n'; root = T.erase(root, k-1); }else{ cout << -1 << '\n'; } } } }