#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int main(){ int q,k; cin >> q >> k; priority_queue pqk; priority_queue,greater> pq; rep(i,q){ int t; cin >> t; if(t==1){ ll v; cin >> v; if(pqk.size()>=k) pq.push(v); else pqk.push(v); }else{ if(pqk.size()==k){ cout << pqk.top() << endl; pqk.pop(); if(pq.size()>0){ pqk.push(pq.top()); pq.pop(); } }else{ cout << -1 << endl; } } } return 0; }