
import java.util.*;
class ArrayStack {
private int maxSize;
private int[] stack;
private int top = -1;
public ArrayStack(int maxSize) {
this.maxSize = maxSize;
stack = new int[this.maxSize];
}
public boolean isFull() {
return top == maxSize - 1;
}
public boolean isEmpty() {
return top == -1;
}
public void push(int value) {
if (isFull()) {
System.out.println("error");
return;
}
top++;
stack[top] = value;
}
public void pop() {
if (isEmpty()) {
System.out.println("error");
} else {
int value = stack[top];
top--;
System.out.println(value);
}
}
public void printTop() {
if (isEmpty()) {
System.out.println("error");
}else{
int value = stack[top];
System.out.println(value);
}
}
}
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.nextLine());
ArrayStack stack = new ArrayStack(n);
while (scan.hasNextLine()) {
String str = (String)scan.nextLine();
String arr[] = str.split(" ");
if (arr[0].equals("push")) {
stack.push(Integer.parseInt(arr[1]));
} else if (arr[0].equals("pop")) {
stack.pop();
} else {
stack.printTop();
}
}
scan.close();
}
}