import sys
from collections import deque
n = int(sys.stdin.readline().rstrip())
list = deque()
for i in range(n):
t = sys.stdin.readline().rstrip()
if 'push' == t.split()[0]:
list.append(t.split()[1])
elif t == 'pop':
if len(list) == 0:
print(-1)
else:
print(list.popleft())
elif t == 'size':
print(len(list))
elif t == 'empty':
if len(list) == 0:
print(1)
else:
print(0)
elif t == 'front':
if len(list) == 0:
print(-1)
else:
print(list[0])
elif t == 'back':
if len(list) == 0:
print(-1)
else:
print(list[-1])