#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using ld = long double; using pii = pair; using pll = pair; #define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++) #define REP(i,n) FOR((i),0,(n)) #define WAITING(str) int str;std::cin>>str; #define DEBUGING(str) cout< 0) { res += bit[i]; i -= i & -i; } return res; } T on(int i) { return sum(i) - (i == 0 ? 0 : sum(i - 1)); } void add(int i, T x) { i++; while (i <= n) { bit[i] += x; i += i & -i; } } //private: ll n; array bit; }; //変数 ll Q, K, kind; vector query; map mp, rev; shared_ptr bit; //サブ関数 //入力 void input() { cin >> Q >> K; ll a = 1, b = 1; set st; REP(i, Q) { cin >> a; if (a == 1) { cin >> b; st.insert(b); } query.push_back({ a,b }); } kind = st.size(); vector order; for (auto num : st)order.push_back(num); sort(order.begin(), order.end()); REP(i, kind) { mp[order[i]] = i; rev[i] = order[i]; } bit = make_unique(kind); } ll type2() { ll l = -1; ll r = kind; while (r - l > 1) { ll mid = (l + r) / 2; if (bit->sum(mid) >= K) { r = mid; } else { l = mid; } } bit->add(r, -1); return rev[r]; } //計算 void calc() { for (const auto& q : query) { if (q.first == 1) { bit->add(mp[q.second], 1); } else { if (bit->sum(kind) < K)cout << -1 << endl; else cout << type2() << endl; } } } //出力 void output() { //cout << bit->on(1) << endl; } //デバッグ void debug() { int N; cin>>N; } //メイン関数 int main() { input(); calc(); output(); debug(); return 0; }