#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define sz(a) int((a).size()) #define rep(i,n) for(int i=0;i<(n);++i) #define ALL(c) c.begin(), c.end() #define tr(container, it) for(auto it = container.begin(); it != container.end(); it++) #define ZEROS(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,-1,sizeof(a)) using namespace std; typedef std::pair< int,int > P; typedef long long ll; struct BIT { int N; vector data; BIT(int N): N(N), data(N+1, 0) {} void add (int x, int val) { while (x <= N) { data[x] += val; x += x & -x; } } ll sum (int x) { ll sum = 0; while (x > 0) { sum += data[x]; x -= x & -x; } return sum; } ll sum_all() { return sum(N); } int query (int k) { if (sum_all() < k) return -1; int lo = 0; int M = 1; while (M <= N) M*=2; for (int i = M/2; i>0; i/=2) { if (lo + i <= N && data[lo + i] < k) { k = k - data[lo + i]; lo = lo + i; } } return lo + 1; } }; BIT bittree(200005); vector values(200005, 0); vector queries(200005, 0); int Q, K; int main () { cin >> Q >> K; vector V; rep(i,Q) { cin >> queries[i]; if (queries[i] == 1) cin >> values[i], V.push_back(values[i]); } sort(ALL(V)); V.erase( unique(ALL(V)), V.end() ); rep(i,Q) { if(queries[i] == 1) { auto it = lower_bound( ALL(V), values[i] ); int ind = it - V.begin(); ind++; bittree.add(ind, 1); } else { int kth_elem = bittree.query(K); if (kth_elem == -1) { cout << -1 << endl; } else { bittree.add(kth_elem, -1); cout << V[--kth_elem] << endl; } } } }