import heapq Q, K = map(int, input().split()) low = [] high = [] for _ in range(Q): s = input() if s[0] == '1': n = int(s.split()[1]) heapq.heappush(low, -n) if len(low) == K: heapq.heappush(high, -heapq.heappop(low)) else: print(-1 if not high else heapq.heappop(high))