import sys
# 명령을 입력받을 변수 n
n = int(sys.stdin.readline())
# 스택(리스트) 선언
stack = []
# for문을 돌면서 명령을 입력받음
for _ in range(n):
word = sys.stdin.readline().split()
order = word[0]
if order == "push":
value = word[1]
stack.append(value)
elif order == "pop":
if len(stack) == 0:
print(-1)
else:
print(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(stack[-1])