#include #include #include using namespace std; using namespace __gnu_pbds; tree, null_type, less>, rb_tree_tag, tree_order_statistics_node_update> t; int main() { ios::sync_with_stdio(0); cin.tie(0); int Q, K; cin >> Q >> K; int id = 0; for (int i = 0; i < Q; ++i) { int op; cin >> op; if (op == 1) { long long v; cin >> v; t.insert({v, id++}); } else { if (t.size() < K) { cout << -1 << '\n'; } else { auto it = t.find_by_order(K - 1); cout << it->first << '\n'; t.erase(it); } } } return 0; }