#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% from heapq import heappushpop, heappush, heappop INF = 10 ** 18 + 10 # %% Q, K = map(int, readline().split()) query = readlines() # %% def solve(): small = [-INF] * (K - 1) large = [] for q in query: if q[0] == ord('1'): x = int(q[2:]) y = -heappushpop(small, -x) heappush(large, y) else: if large: x = heappop(large) if x == INF: yield -1 else: yield x else: yield -1 # %% print('\n'.join(map(str, solve())))