N = int(input())
stack = []
while(N):
order = input()
if order[:4] == 'push':
stack.append(order[4:])
elif order == 'pop':
if len(stack) == 0:
print(-1)
else:
print(int(stack.pop()) )
elif order == 'size':
print( len(stack))
elif order == 'empty':
if len(stack) == 0 :
print(1)
else:
print(0)
elif order == 'top':
if len(stack) == 0:
print(-1)
else:
print(int ( stack[len(stack)-1]) )
N -= 1