from pickle import NONE # import sys # for line in sys.stdin: # a = line.split() # print(int(a[0]) + int(a[1])) class Stack: def __init__(self) -> None: self.stack = [] def push(self,x) -> None: self.stack.append(x) def pop(self) -> None: if len(self.stack) != 0: print(self.stack.pop()) else: print('error') def top(self) -> None: if len(self.stack) != 0: print(self.stack[-1]) else: print('error') # def is_empty(self): # return len(self.stack) == 0 stack = Stack() n=int(input()) for i in range(n): a = [i for i in input().split()] if len(a) == 2: b = int(a[1]) stack.push(b) else: if a[0] == 'pop': stack.pop() else: stack.top()