from os import error
import sys
class My_stack:
def __init__(self):
self.stack_list = []
def push(self, input):
self.stack_list.append(input)
def pop(self):
stack_len = len(self.stack_list)
if stack_len == 0:
print("error")
else:
last_id = stack_len - 1
print(self.stack_list[last_id])
self.stack_list.pop(last_id)
def top(self):
stack_len = len(self.stack_list)
if stack_len == 0:
print("error")
else:
last_id = stack_len - 1
print(self.stack_list[last_id])
lines = []
for line in sys.stdin:
a = line.split()
lines.append(a)
one_stack = My_stack()
for line_id in range(int(lines[0][0])):
one_line = lines[line_id+1]
if one_line[0] == "push":
one_stack.push(int(one_line[1]))
elif one_line[0] == "pop":
one_stack.pop()
elif one_line[0] == "top":
one_stack.top()