#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace __gnu_pbds; static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; template using GPQ = priority_queue, greater>; int main() { int q, k; cin >> q >> k; priority_queue Q; GPQ Q2; while(q--){ int t; scanf("%d", &t); if(t == 1){ ll v; scanf("%lld", &v); Q.emplace(v); if(Q.size() > k) Q2.emplace(Q.top()), Q.pop(); }else { if(Q.size() >= k) { printf("%lld\n", Q.top()); Q.pop(); if(!Q2.empty()) { Q.emplace(Q2.top()); Q2.pop(); } } else puts("-1"); } } return 0; }