#include using namespace std; using int64 = long long; template< class T > struct BinaryIndexedTree { vector< T > data; BinaryIndexedTree(int sz) { data.assign(++sz, 0); } T sum(int k) { T ret = 0; for(++k; k > 0; k -= k & -k) ret += data[k]; return (ret); } void add(int k, T x) { for(++k; k < data.size(); k += k & -k) data[k] += x; } }; template< class T > struct AdditionalBIT : BinaryIndexedTree< T > { int curr; AdditionalBIT(int sz) : BinaryIndexedTree< T >(sz) { curr = 1; while(curr <= sz) curr <<= 1; } int lower_bound(T w) { if(w <= 0) return (0); int i = 0; for(int k = curr; k > 0; k >>= 1) { if(i + k < BinaryIndexedTree< T >::data.size() && BinaryIndexedTree< T >::data[i + k] < w) { w -= BinaryIndexedTree< T >::data[i + k]; i += k; } } return (i); } }; int main() { int Q, K, T[100000]; int64 V[20000]; scanf("%d %d", &Q, &K); vector< int64 > vs; for(int i = 0; i < Q; i++) { scanf("%d", &T[i]); if(T[i] == 1) { scanf("%lld", &V[i]); vs.push_back(V[i]); } } sort(begin(vs), end(vs)); vs.erase(unique(begin(vs), end(vs)), end(vs)); AdditionalBIT< int > bit(vs.size()); int sz = 0; for(int i = 0; i < Q; i++) { if(T[i] == 1) { bit.add(lower_bound(begin(vs), end(vs), V[i]) - begin(vs), 1); ++sz; } else { if(sz < K) { puts("-1"); } else { auto p = bit.lower_bound(K); printf("%lld\n", vs[p]); bit.add(p, -1); --sz; } } } }