import sys
input = sys.stdin.readline
n = int(input().strip())
stack = []
for _ in range(n):
word = input().rstrip()
if word == 'pop':
if not stack:
print(-1)
else:
print(stack.pop())
elif word == 'size':
print(len(stack))
elif word == 'empty':
if stack:
print(0)
else:
print(1)
elif word == 'top':
if not stack:
print(-1)
else:
print(stack[-1])
else:
word, num = word.split()
num = int(num)
stack.append(num)