from heapq import * q, k = map(int, input().split()) qle, qgt = [], [] querys = [map(int, input().split()) for _ in range(q)] for words in querys: if next(words) == 1: v = next(words) if len(qle) k: heappush(qgt, -heappop(qle)) else: heappush(qgt, v) else: if len(qle) < k: print(-1) else: print(-heappop(qle)) if qgt: heappush(qle, -heappop(qgt))