#include using namespace std; using ll = long long; unsigned xor128() { static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned t = x ^ (x << 11); x = y; y = z; z = w; return w = w ^ (w >> 19) ^ (t ^ (t >> 8)); } using T = ll; struct node { T val; node *lch, *rch; int size; node(T v, node* l = nullptr, node* r = nullptr) : val(v), lch(l), rch(r), size(1) {} }; int count(node *t) { return !t ? 0 : t->size; } node *update(node *t) { t->size = count(t->lch) + count(t->rch) + 1; return t; } node *merge(node *l, node *r) { if (!l || !r) return !l ? r : l; if (xor128() % (l->size + r->size) < (unsigned)l->size) { l->rch = merge(l->rch, r); return update(l); } r->lch = merge(l, r->lch); return update(r); } pair split(node *t, int k) { if (!t) return make_pair(nullptr, nullptr); if (k <= count(t->lch)) { pair s = split(t->lch, k); t->lch = s.second; return make_pair(s.first, update(t)); } pair s = split(t->rch, k - count(t->lch) - 1); t->rch = s.first; return make_pair(update(t), s.second); } node *insert(node *t, int k, T v) { pair s = split(t, k); node *r = merge(s.first, new node(v)); r = merge(r, s.second); return r; } node *erase(node *t, int k) { pair s1 = split(t, k), s2 = split(s1.second, 1); if (s2.first != nullptr) delete s2.first; return merge(s1.first, s2.second); } node *find(node *t, int k) { if (t == nullptr) return t; int c = count(t->lch); return k < c ? find(t->lch, k) : k == c ? t : find(t->rch, k - (c + 1)); } int cnt(node *t, T v) { if (t == nullptr) return 0; if (t->val < v) return count(t->lch) + 1 + cnt(t->rch, v); if (t->val == v) return count(t->lch); return cnt(t->lch, v); } int main() { ios::sync_with_stdio(false), cin.tie(0); int Q, K; cin >> Q >> K; node *root = nullptr; while (Q--) { int t; cin >> t; if (t == 1) { ll v; cin >> v; root = insert(root, cnt(root, v), v); } else if (count(root) >= K) { printf("%lld\n", find(root, K - 1)->val); root = erase(root, K - 1); } else { printf("%d\n", -1); } } return 0; }