#include using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll q, k; cin >> q >> k; multisetm1, m2; for (ll i = 0; i < q; i++) { ll type; cin >> type; if (type == 1) { ll val; cin >> val; m1.insert(val); if (m1.size() > k) { ll val1 = *m1.rbegin(); m1.erase(m1.find(val1)); m2.insert(val); } } else { if (m1.size() != k) cout << "-1" << endl; else { ll val1 = *m1.rbegin(); cout << val1 << endl; m1.erase(m1.find(val1)); if (m2.size() >= 1) { ll val2 = *m2.begin(); m2.erase(m2.find(val2)); m1.insert(val2); } } } } }