#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; class BinaryIndexTree { public: vector bit; int N; BinaryIndexTree(int n) { N = n; for (int i = 0; i <= N; ++i) { bit.push_back(0); } } ll sum(int i) { ll ret = 0; while (i > 0) { ret += bit[i]; i -= i & -i; } return ret; } void add(int i, ll x) { while (i <= N) { bit[i] += x; i += i & -i; } } }; int main() { int Q, K; cin >> Q >> K; int T[Q]; ll V[Q]; vector nums; set S; for (int i = 0; i < Q; ++i) { int type; ll v; cin >> type; T[i] = type; if (type == 1) { cin >> v; V[i] = v; if (not S.count(v)) { S.insert(v); nums.push_back(v); } } } sort(nums.begin(), nums.end()); map pos; map val; for (int i = 0; i < nums.size(); ++i) { ll v = nums[i]; pos[v] = i + 1; val[i + 1] = v; } BinaryIndexTree bit(Q + 10); int L = nums.size(); for (int i = 0; i < Q; ++i) { int type = T[i]; if (type == 1) { ll v = V[i]; int idx = pos[v]; bit.add(idx, 1); } else { int sum = bit.sum(L); if (sum < K) { cout << -1 << endl; } else { int ng = 0; int ok = L; while (abs(ok - ng) >= 2) { int idx = (ok + ng) / 2; ll k = bit.sum(idx); if (K <= k) { ok = idx; } else { ng = idx; } } bit.add(ok, -1); cout << val[ok] << endl; } } } return 0; }