#include #include #include #include #include #include #include #include #include #include #pragma GCC optimize("O3") #pragma comment(linker, "STACK:36777216") using namespace std; using i64 = int64_t; constexpr i64 MOD = 1e9 + 7; using vi = vector; using vvi = vector; using vvvi = vector; int main() { cin.tie(0); ios::sync_with_stdio(0); priority_queue small; priority_queue> big; int q, k; cin >> q >> k; int type; i64 v; for (int i = 0; i < q; i++) { cin >> type; if (type == 1) { cin >> v; if (small.size() < k) { small.push(v); } else { i64 t = small.top(); if (v > t) { big.push(v); } else { big.push(small.top()); small.pop(); small.push(v); } } } else { if (small.size() < k) { cout << "-1" << endl; } else { cout << small.top() << endl; if (big.size()) { small.pop(); small.push(big.top()); big.pop(); } else { small.pop(); } } } } }