/*
#include <stdio.h>
#define SIZE 100000
int stack [SIZE]={};
int top=-1;
void push (int data)
{
stack[++top]=data;
}
int pop ()
{
return stack [top--];
}
int main ()
{
int k,a=0,i,sum=0;
scanf ("%d",&k);
for (i=1;i<=k;i++)
{
scanf ("%d",&a);
if(a==0)
{
pop();
}
else
{
push(a);
}
}
k=top+1;
for(i=0;i<k;i++)
{
sum+=pop();
}
printf("%d",sum);
return 0;
}
*/
/*
#include <stdio.h>
#define SIZE 50001
#include <string.h>
int stack [SIZE]={};
int top=-1;
void push (int data)
{
stack [++top]=data;
}
int pop ()
{
return stack [top--];
}
int main ()
{
int i;
char str[SIZE];
gets (str);
for (i=0;i<strlen(str);i++)
{
if (str[i]==')')
{
pop ();
if (top==-2)
{
break;
}
}
else
{
push (str[i]);
}
}
if (top==-1)
{
printf ("good");
}
else
{
printf ("bad");
}
return 0;
}
*/
#include <stdio.h>
#define SIZE 200
int stack [SIZE]={};
int top=-1;
void push (int data)
{
stack [++top]=data;
}
int pop ()
{
return stack [top--];
}
int main ()
{
int n,i,j,c=0;
char str[SIZE];
scanf ("%d ",&n);
for (i=0;i<n;i++)
{
gets(str);
if(str[1]=='u')
{
push (c);
}
else if(str[0]=='t')
{
printf ("%d\n",pop());
}
else if (str[2]=='p'&&str[0]=='p')
{
pop ();
}
else if (str[0]=='s')
{
}
return 0;
}