import sys
stack = []
N = int(sys.stdin.readline())
for i in range(N):
cmd = sys.stdin.readline().split()
if cmd[0] == 'push':
stack.append(cmd[1])
elif cmd[0] == 'pop':
if stack: print(stack.pop())
else: print(-1)
elif cmd[0] == 'size':
print(len(stack))
elif cmd[0] == 'empty':
if stack: print(0)
else: print(1)
else:
if stack: print(stack[-1])
else: print(-1)