#!/usr/bin/env python Q = int(input()) events = [] for i in range(Q): events.append([int(x) for x in input().split()]) labo_indexs = {} for (i, event) in enumerate(events): if event[0] == 1: labo_indexs[i+1] = 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()]) vals = labo_indexs.values() for l in range(len(vals), -1, -1): if len([x for x in vals if x >= l]) >= l: print(l) break else: continue