import sys #필요한 것을import해온다
stack = [] #스택 생성
n = int(sys.stdin.readline())
for _ in range(n):
x = sys.stdin.readline().strip()
#x에 명령어를 집어넣는다. push의 경우 숫자가 함께 들어올 걸 대비하여 strip로 분리한다.
if x.startswith('push'):
_, y = x.split()
stack.append(int(y))
#_는 명령어, y는 숫자값이다.
elif x == 'pop':
print(stack.pop() if stack else -1)
#삼항연산자이다. A if 조건 else B라는 것이 있다고 가정한다. 조건이 참이면 A 실행, 거짓이면 B 실행한다.
elif x == 'size':
print(len(stack))
elif x == 'empty':
print(0 if stack else 1)
elif x == 'top':
print(stack[-1] if stack else -1)
#나머지는 문제에 쓰인 그대로이다.