import sys import heapq input = sys.stdin.readline Q, K = map(int, input().split()) low = [] high = [] for _ in range(Q): query = list(map(int, input().split())) if len(query) == 2: heapq.heappush(low, -query[1]) if len(low) > K: x = -heapq.heappop(low) heapq.heappush(high, x) else: if len(low) < K: print(-1) else: print(-heapq.heappop(low)) if high: x = heapq.heappop(high) heapq.heappush(low, -x)