from sortedcontainers import SortedList from collections import defaultdict S = SortedList([]) N, Q = map(int, input().split()) dic1 = defaultdict(int) dic2 = defaultdict(int) ans = [] for _ in range(Q): t, *sr = input().split() if t == "1": s, r = sr r = int(r) dic1[s] = r dic2[s] = 1 S.add((1, -r, s)) tmp = [] if N < len(S): a, b, s = S.pop(-1) ans.append(s) elif t == "2": x = int(sr[0]) N = max(0, N - x) tmp = [] while N < len(S): a, b, s = S.pop(-1) tmp.append((b, s)) tmp.sort(reverse=True) for t, s in tmp: ans.append(s) else: s, x = sr x = int(x) N += x if dic2[s] == 1: S.remove((1, -dic1[s], s)) S.add((0, -dic1[s], s)) dic2[s] = 0 for s in ans: print(s)