#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; struct typeA { ll v; }; bool operator<(const typeA& a, const typeA& b){ return a.v < b.v; } struct typeB { ll v; }; bool operator<(const typeB& a, const typeB& b){ return a.v > b.v; } class Kth { int K; int sz; priority_queue aque; priority_queue bque; public: Kth(int K):sz(0),K(K){} int size() const { return sz; } void add(ll v){ sz++; aque.push((typeA){v}); if(aque.size() <= K) return; typeA x = aque.top(); aque.pop(); bque.push((typeB){x.v}); } ll pop(){ if(aque.size() < K) return -1; sz--; typeA x = aque.top(); aque.pop(); if(bque.size() > 0){ typeB y = bque.top(); bque.pop(); aque.push((typeA){y.v}); } return x.v; } }; int main(){ int Q, K; cin >> Q >> K; Kth kth(K); rep(i,Q){ int type; cin >> type; if(type == 1){ ll v; cin >> v; kth.add(v); }else{ cout << kth.pop() << endl; } } return 0; }