# Enter your code here. Read input from STDIN. Print output to STDOUT
n = int(raw_input().strip())
stack =[]
maxi = [0]
for _ in range(n):
    cmd = map(int,raw_input().split())
    if cmd[0]==1:
        stack.append(cmd[1])
        if cmd[1]>=maxi[-1]:
            maxi.append(cmd[1])
    elif cmd[0] == 2:
        if stack.pop()==maxi[-1]:
            maxi.pop()
    elif cmd[0] == 3:
        print(maxi[-1])

results matching ""

    No results matching ""