import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 记录操作数
        int optNum = in.nextInt();
        // 定义一个长度=操作数的数组
        int[] stack = new int[optNum];
        // 定义栈顶指针记录栈使用情况
        int top = -1;
        while (in.hasNextLine()) {
            // 获取当前输入的字符串
            String optText = in.nextLine();
            // 字符串以push开头->入栈
            if (optText.startsWith("push")) {
                String pushNumStr = optText.substring(5);
                int pushNum = Integer.parseInt(pushNumStr);
                stack[++top] = pushNum;
            }
            // 字符串以pop开头 -> 出栈(无输出)
            if (optText.startsWith("pop")) {
                // 栈为空
                if (top == -1) {
                    System.out.println("error");
                } else {
                    System.out.println(stack[top--]);
                }
            }
            // 字符串以top开头 -> 输出栈顶元素
            if (optText.startsWith("top")) {
                if (top == -1) {
                    System.out.println("error");
                } else {
                    System.out.println(stack[top]);
                }
            }
        }
    }
}