#include<stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    char s[10];
    int stack[n],i=0,num;
    while(n--)
    {
        scanf("%s",&s);
        if(s[1]=='u')
        {
            scanf("%d ",&num);
            stack[i++]=num;
        }
        else if(s[1]=='o')
        {
            if(s[0]=='p')
            {
                if(i>0)
                {
                    printf("%d\n",stack[i-1]);
                    i--;
                }
                else{
                    printf("error\n");
                }
            }
            else if(s[0]=='t')
            {
                if(i>0)
                {
                    printf("%d\n",stack[i-1]);
                }
                else{
                    printf("error\n");
                }
            }
        }
    }
    return 0;
}