#include using namespace std; template class RBST{ public: struct node{ S v, sum; node *l, *r; int cnt; node(S v): v(v), sum(v), cnt(1){ l = r =nullptr; } }; unsigned long xor128(){ static unsigned long x=123456789,y=362436069,z=521288629,w=88675123; unsigned long t; t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } vector delete_nodes; S op(S x, S y){return x^y;}; node *root=nullptr; int size(node *t){return !t ? 0 : t->cnt;} S sum(node *t){return !t ? 0 : t->sum;} node *update(node *t){ node *l=t->l, *r=t->r; t->cnt=1+size(l)+size(r); t->sum=op(op(sum(l),t->v),sum(r)); return t; } node *merge(node *l, node *r){ if (!l || !r)return !l ? r : l; if (xor128()%(size(l)+size(r))r=merge(l->r,r); return update(l); }else{ r->l=merge(l,r->l); return update(r); } } pair split(node *t, int k){ if (!t)return {nullptr, nullptr}; if (k<=size(t->l)){ pair s=split(t->l, k); t->l=s.second; return make_pair(s.first, update(t)); }else{ pair s=split(t->r, k-size(t->l)-1); t->r=s.first; return make_pair(update(t), s.second); } } S lower_bound(node *t, S k){ if (!t)return 0; if (t->vl)+1+lower_bound(t->r, k); else return lower_bound(t->l, k); } S upper_bound(node *t, S k){ if (!t)return 0; if (t->v<=k)return size(t->l)+1+upper_bound(t->r, k); else return upper_bound(t->l, k); } S get(node *t, int k){ int s=size(t->l); if (s>k)return get(t->l, k); else if (sr, k-size(t->l)-1); else return t->v; } node *insert(node *t, S v){ int k=lower_bound(t, v); auto s=split(t, k); node *n=new node(v); return merge(merge(s.first, n), s.second); } pair erase(node *t, int k){ auto sl=split(t, k+1); auto sr=split(sl.first, k); delete_nodes.push_back(sr.second); if (delete_nodes.size()>1000)delete_nodes.clear(); return make_pair(merge(sr.first, sl.second), sr.second); } tuple prod(node *t, int l, int r){ auto sr=split(t, r); auto sl=split(sr.first, l); return make_tuple(sl.first, sl.second, sr.second); } public: int size(){return size(root);} void insert(S v){root=insert(root, v);} void erase(int k){root=erase(root, k).first;} S get(int k){return get(root, k);} S lower_bound(S k){return lower_bound(root, k);} S upper_bound(S k){return upper_bound(root, k);} S prod(int l, int r){ auto [left,mid,right]=prod(root, l, r); S res=sum(mid); root=merge(merge(left,mid),right); return res; } }; int main() { RBST st; int q,k; cin >> q >> k; while (q--){ long long t,x; cin >> t; if (t==1){ cin >> x; st.insert(x); }else { if (k<=st.size()){ cout << st.get(k-1) << endl; st.erase(k-1); }else{ cout << -1 << endl; } } } }