#include <bits/stdc++.h>

typedef long long LL;

const int N = 1e5 + 7;
const int MOD = 998244353;

int n, m, a[N], ans;
std::multiset<LL> big, small;

int main() {

  scanf("%d%d", &n, &m);

  while(n--) {
    LL t, x;
    scanf("%lld", &t);
    if(t == 1) {
      scanf("%lld", &x);
      small.insert(x);
      if(small.size() >= m) {
	big.insert(*small.rbegin());
	small.erase(--small.end());
      }
    }
    else {
      if(!big.empty()) {
	printf("%lld\n", *big.begin());
	big.erase(big.begin());
      }
      else
	puts("-1");
    }
  }
  
  return 0;

}