import sys
class Stack():
def __init__(self) -> None:
self.item = []
def push(self, x):
self.item.append(x)
def pop(self):
if self._is_empty():
print("error")
else:
print(self.item[-1])
self.item.pop()
def top(self):
if self._is_empty():
print("error")
else:
print(self.item[-1])
def _is_empty(self):
return True if len(self.item) == 0 else False
my_stack = Stack()
n = int(input())
for i in range(n):
command = input().split()
if command[0] == "push":
my_stack.push(command[1])
elif command[0] == "pop":
my_stack.pop()
elif command[0] == "top":
my_stack.top()