#include using namespace std; using ll = long long; using ul = unsigned long; using ull = unsigned long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll q, k; cin >> q >> k; priority_queue ql; priority_queue, greater > qr; stringstream ss; for (ll i = 0; i < q; ++i) { int t; cin >> t; if (t == 1) { ll v; cin >> v; if ((int)ql.size() < k) ql.push(v); else { ll qlt = ql.top(); if (qlt > v) { ql.pop(); ql.push(v); qr.push(qlt); } else qr.push(v); } } else { if ((int)ql.size() >= k) { ss << ql.top() << "\n"; ql.pop(); if (!qr.empty()) { ql.push(qr.top()); qr.pop(); } } else ss << "-1\n"; } } cout << ss.str(); return 0; }