#include using namespace std; using ll = long long; template class BinaryIndexedTree { public: using T = typename Base::T; using AbelGroup = Base; BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); } BinaryIndexedTree(const vector& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { for (int i = 1; i <= data_num; i++) { value[i] = val[i - 1]; } for (int x = 1; x < size; x++) { value[x + (x & -x)] = op(value[x + (x & -x)], value[x]); } } T accumulate(const int a) const { assert(0 <= a and a < data_num); int ind = a + 1; T sum = AbelGroup::identity(); while (ind > 0) { sum = op(sum, value[ind]); ind &= ind - 1; } return sum; } T accumulate(const int l, const int r) const // [l,r) { assert(0 <= l and l < r and r <= data_num); return op(accumulate(r - 1), op.inv(l == 0 ? AbelGroup::identity() : accumulate(l - 1))); } void add(const int a, const T& val) { assert(0 <= a and a < data_num); int ind = a + 1; while (ind <= size) { value[ind] = op(value[ind], val); ind += ind & (-ind); } } void set(const int a, const T& val) { const int v = get(a); add(a, op(val, op.inv(v))); } T get(const int a) const { assert(0 <= a and a < data_num); return accumulate(a, a + 1); } int lowerBound(T w) const { if (w <= AbelGroup::identity()) { return 0; } int x = 0; for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) { if (x + k <= size and value[x + k] < w) { w = op(w, op.inv(value[x + k])); x += k; } } return x; } int upperBound(T w) const { if (w <= AbelGroup::identity()) { return 0; } int x = 0; for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) { if (x + k <= size and value[x + k] <= w) { w = op(w, op.inv(value[x + k])); x += k; } } return min(x, data_num); } private: const int data_num; const int size; const AbelGroup op{}; vector value; }; template ostream& operator<<(ostream& os, const BinaryIndexedTree& bit) { os << "["; for (int i = 0; i < bit.data_num; i++) { os << bit.get(i) << ","; } os << "]" << endl; return os; } struct Sum { using T = ll; T operator()(const T& a, const T& b) const { return a + b; } T inv(const T& a) const { return -a; } static constexpr T identity() { return 0; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int Q, K; cin >> Q >> K; using P = pair; vector

query(Q); vector v; for (int q = 0; q < Q; q++) { cin >> query[q].first; if (query[q].first == 1) { cin >> query[q].second; v.push_back(query[q].second); } } auto zip = v; sort(zip.begin(), zip.end()); zip.erase(unique(zip.begin(), zip.end()), zip.end()); map mp; const int size = zip.size(); if (size != 0) { for (int i = 0; i < zip.size(); i++) { mp[zip[i]] = i; } BinaryIndexedTree bit(size); for (int q = 0; q < Q; q++) { if (query[q].first == 1) { const int t = mp[query[q].second]; bit.add(t, 1); } else { if (bit.accumulate(size - 1) < K) { cout << -1 << "\n"; } else { const int l = bit.lowerBound(K); cout << zip[l] << "\n"; bit.add(l, -1); } } } } else { for (int q = 0; q < Q; q++) { cout << -1 << endl; } } return 0; }