#include <stdio.h>
#include <string.h>
struct Stack
{
int str[100000];
int top;
};
typedef struct Stack* Pstack;
Pstack inistack(void)
{
Pstack s = (struct Stack *)malloc(sizeof(struct Stack));
s->top = -1;
return s;
}
void push(Pstack s, int x)
{
s->str[s->top + 1] = x;
s->top++;
}
int pop(Pstack s)
{
int ans;
ans = s->str[s->top];
s->top--;
return ans;
}
int top(Pstack s)
{
return s->str[s->top];
}
int main()
{
int n, i, ret, t, res;
char op[5];
Pstack s;
s = inistack();
scanf("%d",&n);
for(i = 0; i < n; i++)
{
ret = scanf("%s %d",op, &t);
if(ret == 1)
{
if(strcmp(op,"pop") == 0)
{
if(s->top == -1)
{
printf("error\n");
}
else
{
res = pop(s);
printf("%d\n",res);
}
}
else
{
if(s->top == -1)
{
printf("error\n");
}
else
{
res = top(s);
printf("%d\n",res);
}
}
}
else
{
push(s,t);
}
}
return 0;
}