class Stack:
    def __init__(self) -> None:
        self.items = []

    def push(self, item:int):
        self.items.append(int(item))


    def pop(self):
        if not len(self.items):
            print("error")
        else:
            print(self.items.pop())

    def top(self):
        if not len(self.items):
            print("error")
        else:
            print(self.items[-1])


stack = Stack()
n = int(input())
for i in range(n):
    ls = input().split()
    if len(ls) == 2:
        stack.push(ls[1])
    elif len(ls) == 1:
        if ls[0] == "pop":
            stack.pop()
        elif ls[0] == "top":
            stack.top()