import sys input = sys.stdin.readline from heapq import * Q, K = map(int, input().split()) H1, H2 = [], [] cnt = 0 for _ in range(Q): query = list(map(int, input().split())) if query[0] == 1: v = query[1] if cnt < K: heappush(H1, -v) cnt += 1 else: maxv = -heappop(H1) if v <= maxv: heappush(H1, -v) heappush(H2, maxv) else: heappush(H1, -maxv) heappush(H2, v) else: if cnt < K: print(-1) else: print(-heappop(H1)) if H2: minv = heappop(H2) heappush(H1, -minv) else: cnt -= 1