#!/usr/bin/env python Q = int(input()) events = [] for i in range(Q): events.append([int(x) for x in input().split()]) i = 1 labo_indexs = {} for event in events: if event[0] == 1: labo_indexs[i] = event[1] elif event[0] == 2: del labo_indexs[event[1]] elif event[0] == 3: labo_indexs = dict([(x, y+event[1]) for (x, y) in labo_indexs.items()]) i += 1 vals = labo_indexs.values() for j in range(len(vals), -1, -1): if len([x for x in vals if x >= j]) >= j: print(j) break else: continue