import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
Stack<Integer> s = new Stack<>();
String[] ins;
int n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
ins = br.readLine().split(" ");
if (ins[0].equals("push")) {
s.push(Integer.parseInt(ins[1]));
} else if (ins[0].equals("pop")) {
if (s.empty()) {
sb.append(-1).append('\n');
} else {
sb.append(s.pop()).append('\n');
}
} else if (ins[0].equals("size")) {
sb.append(s.size()).append('\n');
} else if (ins[0].equals("empty")) {
if (s.empty()) {
sb.append("1").append('\n');
} else {
sb.append("0").append('\n');
}
} else if (ins[0].equals("top")) {
if (s.empty()) {
sb.append("-1").append('\n');
} else {
sb.append(s.peek()).append('\n');
}
} else {
System.out.println("ERROR");
}
}
System.out.println(sb.toString());
br.close();
return;
}
}