#include <stdio.h>
#include <string.h>
int stack[201]={};
int top=-1;
void push(int n)
{
top++;
stack[top]=n;
}
int main()
{
int n,i;
char scan[50];
scanf("%d ",&n);
for(i=0;i<n;i++)
{
gets(scan);
if(scan[0]=='p'&&scan[1]=='u'){
push(scan[6]-'0');
}
else if(scan[0]=='t') {
if(top==-1) printf("-1\n");
else printf("%d\n",stack[top]);
}
else if(scan[0]=='p'&&top>-1) top--;
else if(scan[0]=='s') {
printf("%d\n",top+1);
}
else if(scan[0]=='e'){
if(top==-1) printf("true\n");
else printf("false\n");
}
}
return 0;
}



