#include #include using lint = long long; void solve() { int q, k; std::cin >> q >> k; std::multiset big, small; auto insert = [&](lint x) { big.insert(x); if ((int)big.size() >= k) { lint y = *big.rbegin(); big.erase(big.find(y)); small.insert(y); } }; while (q--) { int t; std::cin >> t; switch (t) { case 1: { lint x; std::cin >> x; insert(x); break; } case 2: { if (small.empty()) { std::cout << -1 << "\n"; } else { auto x = *small.begin(); small.erase(small.find(x)); std::cout << x << "\n"; } } } } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }