#include using namespace std;long long K,V;multiset a,b;main(){for(cin>>V>>K;cin>>V;)if(V<2){cin>>V;a.insert(-V);if(a.size()==K){auto i=a.begin();b.insert(-*i);a.erase(i);}}else{if(b.size()){auto i=b.begin();cout<<*i<