from heapq import * from collections import defaultdict N, Q0 = map(int, input().split()) dic1 = defaultdict(int) dic2 = defaultdict(int) Q = [] ans = [] upd = set() for q in range(Q0): t, *sr = input().split() if t == "1": s, r = sr r = int(r) dic1[s] = r dic2[s] = 0 heappush(Q,(0, r, s)) tmp = [] while N + len(upd) < len(Q): a, b, s = heappop(Q) if a == 0 and (a,b,s) in upd: upd.remove((a,b,s)) continue tmp.append((b,s)) tmp.sort() for t, s in tmp: ans.append(s) elif t == "2": x = int(sr[0]) N = max(0, N - x) tmp = [] while N + len(upd) < len(Q): a, b, s = heappop(Q) if a == 0 and (a,b,s) in upd: upd.remove((a,b,s)) continue tmp.append((b,s)) tmp.sort() for t, s in tmp: ans.append(s) else: s, x = sr x = int(x) N += x if dic2[s] == 0: upd.add((0,dic1[s], s)) heappush(Q,(1,dic1[s],s)) dic2[s] = 1 for s in ans: print(s)