#include <stdio.h>
int fin[600];
int top=0;
char s[100];
void push()
{
int x=0;
int i=5;
int sign=1;
if(s[i]=='-')
{
sign=-1;
i=i+1;
}
while(s[i]>='0'&&s[i]<='9')
{
x=x*10+(s[i]-'0');
i=i+1;
}
fin[top]=sign*x;
top=top+1;
}
void topff()
{
if(top==0)
{
printf("-1\n");
}
else
{
printf("%d\n",fin[top-1]);
}
}
void pop()
{
if(top==0)
{
printf("-1\n");
}
else
{
printf("%d\n",fin[top-1]);
top=top-1;
}
}
void size()
{
printf("%d\n",top);
}
void empty()
{
if(top==0)
{
printf("true\n");
}
else
{
printf("false\n");
}
}
int main()
{
char buf[20];
gets(buf);
int n=0;
int j=0;
while(buf[j]>='0'&&buf[j]<='9')
{
n=n*10+(buf[j]-'0');
j=j+1;
}
int i=0;
while(i<n)
{
gets(s);
if(s[0]=='p'&&s[1]=='u')
{
push();
}
else if(s[0]=='t')
{
topff();
}
else if(s[0]=='p'&&s[1]=='o')
{
pop();
}
else if(s[0]=='s')
{
size();
}
else if(s[0]=='e')
{
empty();
}
i=i+1;
}
return 0;
}



