#include #include using namespace std; #define int long long const int N = 2e5 + 5; int q,k; multiset s1,s2; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> q >> k; while(q--) { int opt, x; cin >> opt; if(opt == 1) { cin >> x; if(s1.size() < k) s1.insert(x); else if(x < *(--s1.end())) { s2.insert(*(--s1.end())); s1.erase(--s1.end()); s1.insert(x); } else s2.insert(x); } else { if(s1.size() < k) cout << -1 << '\n'; else { cout << *(--s1.end()) << '\n'; s1.erase(--s1.end()); if(s2.size()) s1.insert(*s2.begin()), s2.erase(s2.begin()); } } } return 0; }