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: yield -1 else: yield -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() def out(x): if isinstance(x, List) or isinstance(x, Tuple): print(*x) else: print(x) if ret is None: pass elif isinstance(ret, Generator): for val in ret: out(val) else: out(ret)