import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
while(input.hasNext()) {
int times=input.nextInt();
int []a=new int [20000];
int t=0;
for(int i=1;i<=times;i++) {
String st=input.next();
int temp;
if(st.equals("push")) {
temp=input.nextInt();
t++;
a[t]=temp;
}
else if(st.equals("top")) {
if(t==0)System.out.println("empty");
else System.out.println(a[t]);
}
else if(st.equals("pop")) {
if(t==0)System.out.println("error");
else {
a[t]=0;
t--;
}
}
}
System.out.println();
}
input.close();
}
}