import sys from typing import Generator, List, Tuple import heapq def input(): return sys.stdin.readline().rstrip('\n') def main(): q, k = map(int, input().split()) topk = [] bot = [] for _ in range(q): qry = input() if qry == '2': if len(topk) < k: print(-1) else: print(-topk[0]) heapq.heappop(topk) if bot: el = heapq.heappop(bot) heapq.heappush(topk, -el) else: _, v = map(int, qry.split()) heapq.heappush(topk, -v) if len(topk) > k: el = -heapq.heappop(topk) heapq.heappush(bot, el) if __name__ == '__main__': ret = main() buffer = [] def out(x): if isinstance(x, List) or isinstance(x, Tuple): buffer.append(' '.join(map(str, x))) else: buffer.append(str(x)) if ret is None: pass elif isinstance(ret, Generator): for val in ret: out(val) else: out(ret) if buffer: sys.stdout.write('\n'.join(buffer))