import java.util.*;
class MyStack1 {
//设置两个栈
private Stack<Integer> spush;
private Stack<Integer> spop;
public MyStack1(){
this.spush=new Stack<Integer>();
this.spop=new Stack<Integer>();
}
//只要pop栈为空,就可以直接往Push栈里增加数据
public void add(int num){
// 把pop栈的数据全部弹到push栈
while (!spop.isEmpty()){
spush.push(spop.pop());
}
spop.push(num);
}
//取最小值
public int peek(){
if(spop.isEmpty()&&spush.isEmpty()){
throw new RuntimeException("all null");
}
//为了模拟队列先进先出,用push进,那么只能从Pop里弹
//先把push的数据放入pop里,再从pop找最小值
while (!spush.isEmpty()){
spop.push(spush.pop());
}
return spop.peek();
}
//弹出pop的第一个数据
public void poll(){
peek();
spop.pop();
}
}
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
MyStack1 stack1 = new MyStack1();
int t = scan.nextInt();
for(int i=0;i<t;i++){
String op=scan.next();
if(op.equals("add")){
int x= scan.nextInt();
stack1.add(x);
}else if(op.equals("peek")){
System.out.println(stack1.peek());
}else if(op.equals("poll")){
stack1.poll();
}
}
}
}