#include using namespace std; using ll = long long; //1-indexであることに注意 template struct BIT { int n; vector data; BIT(int n) : n(n), data(n + 1, 0) {} T sum(int i) { T s = 0; while (i > 0) { s += data[i]; i -= i & -i; } return s; } void add(int i, T x) { while (i <= n) { data[i] += x; i += i & -i; } } }; //引数unzipには圧縮前のvectorを入れる int compress(vector& unzip, map& zip) { sort(unzip.begin(), unzip.end()); unzip.erase(unique(unzip.begin(), unzip.end()), unzip.end()); for (int i = 0; i < unzip.size(); i++) { zip[unzip[i]] = i; } return unzip.size(); } int main() { cin.tie(0); ios::sync_with_stdio(false); int Q, K; cin >> Q >> K; vector q(Q); vector v; for (int i = 0; i < Q; i++) { cin >> q[i]; if (q[i] == 1) { ll x; cin >> x; v.push_back(x); q[i] = x; } else { q[i] = -1; } } map zip; compress(v, zip); BIT b(v.size()); for (int i = 0; i < Q; i++) { if (q[i] == -1) { if (b.sum(v.size()) < K) { cout << -1 << endl; } else { int ng = 0, ok = v.size(); while (ok - ng > 1) { int mid = (ok + ng) / 2; if (b.sum(mid) >= K) ok = mid; else ng = mid; } cout << v[ok - 1] << endl; b.add(ok, -1); } } else { b.add(zip[q[i]] + 1, 1); } } return 0; }