class Stack():
    def __init__(self):
        self.item=[]
    def push(self,x):
        self.item.append(x)
    def pop(self):
        x=self.item.pop()
        return x
    def top(self):
        return self.item[-1]
    def size(self):
        return len(self.item)    

stack1=Stack()

n=int(input())
for i in range(n):
    a=input()
    if a[0:4]=='push':
        b=a.split(' ')
        stack1.push(int(b[1]))
    elif a=='pop':
        if stack1.size()==0:
            print('error')
        else:
            x=stack1.pop()
            print(x)
    else:
        if stack1.size()==0:
            print('error')
        else:
            print(stack1.top())