#include using namespace std; signed main() { ios::sync_with_stdio(false); int Q, K; cin >> Q >> K; priority_queue lpq, gpq; for (int qi = 0; qi < Q; ++qi) { int OP; cin >> OP; if (OP == 1) { int64_t V; cin >> V; if (lpq.size() < K) { lpq.emplace(V); } else { if (V >= lpq.top()) { gpq.emplace(-V); } else { lpq.emplace(V); gpq.emplace(-lpq.top()); lpq.pop(); } } } else { if (lpq.size() < K) { cout << -1 << endl; } else { cout << lpq.top() << endl; lpq.pop(); if (gpq.size()) { lpq.emplace(-gpq.top()); gpq.pop(); } } } } return 0; }