#include using namespace std; int main() { int Q, K; cin >> Q >> K; multiset bag0; multiset bag1; while (Q--) { int P; cin >> P; if (P == 1) { int64_t V; cin >> V; bag0.insert(V); if (bag1.size() && *bag1.begin() < *--bag0.end()) { bag1.insert(*--bag0.end()); bag0.erase(--bag0.end()); } } else { if (bag0.size() == K) { cout << *--bag0.end() << endl; bag0.erase(--bag0.end()); } else { cout << -1 << endl; } } while (bag0.size() < K && bag1.size()) { bag0.insert(*bag1.begin()); bag1.erase(bag1.begin()); } while (bag0.size() > K) { bag1.insert(*--bag0.end()); bag0.erase(--bag0.end()); } } return 0; }