#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<stack>
using namespace std;
int top=0;
int st[311001];
void pushn(int x){
top++;
st[top]=x;
}
void pop(){
top--;
}
int searchm(){
int maxx=0;
for(int i=1;i<=top;i++){
if(st[i]>maxx){
maxx=st[i];
}
}
return maxx;
}
int main(){
int n,a,b;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a;
if(a==0){
cin>>b;
pushn(b);
}
if(a==1){
pop();
}
if(a==2){
cout<<searchm()<<endl;
}
}
return 0;
}