# from sortedcontainers import SortedSet, SortedList, SortedDict # S1 = SortedList([]) # S2 = SortedList([]) S1 = [] S2 = [] N, Q = map(int, input().split()) now = N rate = dict() out = [] for q in range(Q): L = list(map(str, input().split())) if L[0] == '1': s, r = L[1], int(L[2]) # レートr、名前sが来る rate[s] = r # S2.add((r, s)) S2.append((r, s)) elif L[0] == '2': x = int(L[1]) # x個のpcが壊れる now -= x elif L[0] == '3': s, x = L[1], int(L[2]) # 名前sがx個を治す now += x if (rate[s], s) in S2: S2.remove((rate[s], s)) S1.append((rate[s], s)) # S2.discard((s, rate[s])) # S1.add((s, rate[s])) # 退場 N1 = len(S1) N2 = len(S2) Ntot = N1 + N2 Nout = Ntot - now outnow = [] outN2 = min(Nout, N2) outN1 = Nout - outN2 S1.sort(reverse=True) S2.sort(reverse=True) for i in range(outN2): a = S2.pop() outnow.append(a) for i in range(outN1): a = S1.pop() outnow.append(a) outnow.sort() for r,s in outnow: out.append(s) for item in out: print(item)