#include <stdio.h>
#include <string.h>
#define SIZE 10000
int res[SIZE] = {0};
int N;
int count = 0;
void push(int input){
res[count] = input;
count++;
}
void pop(){
if(count == 0){
printf("-1\n");
return;
}
printf("%d\n",res[count-1]);
res[count - 1] = 0;
count--;
}
void size(){
printf("%d\n",count);
}
void empty(){
if(count == 0){
printf("1\n");
}
else{
printf("0\n");
}
}
void top(){
if(count == 0){
printf("-1\n");
}
else{
printf("%d\n",res[count -1]);
}
}
int main() {
scanf("%d", &N);
char input[10] = {};
for (int i = 0; i < N; i++) {
scanf("%s", &input);
//printf("%s\n",input);
if(strcmp(input,"push") == 0){
int temp;
scanf("%d",&temp);
push(temp);
continue;
}
else if(strcmp(input,"pop") == 0){
pop();
continue;
}
else if(strcmp(input,"size") == 0){
size();
continue;
}
else if(strcmp(input,"empty") == 0){
empty();
continue;
}
else if(strcmp(input,"top") == 0){
top();
continue;
}
}
return 0;
}