#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
int n, x;
scanf("%d", &n);
stack<int> stk;
char op[10];
for (int i = 0; i < n; i++){
scanf("%s", op);
if (strcmp(op, "push") == 0){
scanf("%d", &x);
stk.push(x);
}
else if (strcmp(op, "pop") == 0){
if (stk.empty())
printf("-1\n");
else{
printf("%d\n", stk.top());
stk.pop();
}
}
else if (strcmp(op, "size") == 0)
printf("%d\n", stk.size());
else if (strcmp(op, "empty") == 0)
printf("%d\n", stk.empty());
else{
if (stk.empty())
printf("-1\n");
else
printf("%d\n", stk.top());
}
}
}