Q,K=map(int,input().split()) A=[] B=[] import heapq import sys input=sys.stdin.readline heapq.heapify(A) heapq.heapify(B) for i in range(Q): C=list(map(int,input().split())) #print(C) if len(C)==1: if len(B)==0: print(-1) else: a=heapq.heappop(B) print(a) else: if len(A)(-1*C[1]): heapq.heappush(B,C[1]) else: heapq.heappush(A,-C[1]) c=heapq.heappop(A) heapq.heappush(B,-c)