n = int(input())  # 输入操作次数
stack = []  # 栈
for _ in range(n):
    op = input().split()  # 分割操作字符串
    if op[0] == "push":
        stack.append(int(op[1]))  # 入栈操作
    elif op[0] == "pop":
        if not stack:
            print("error")
        else:
            print(stack.pop())  # 出栈操作
    elif op[0] == "top":
        if not stack:
            print("error")
        else:
            print(stack[-1])  # 输出栈顶元素