from heapq import heappush, heappop import sys def input(): return sys.stdin.buffer.readline()[:-1] n, k = map(int, input().split()) q1, q2 = [], [] def add(x): heappush(q1, -x) if len(q1) > k: tmp = heappop(q1) heappush(q2, -tmp) return def remove(): if len(q1) < k: return -1 else: res = heappop(q1) if q2: nxt = heappop(q2) heappush(q1, -nxt) return -res for _ in range(n): t = input().split() if len(t) == 2: add(int(t[1])) else: print(remove())