#include<iostream>
#include<map>
using namespace std;
map<int,int> a;
int main(){
int t;
cin>>t;
while(t--){
int i;
cin>>i;
if(i==1){
int x;
cin>>x;
if(a.count(x)!=0){
a[x]++;
}
a.insert(make_pair(x,1));
}
else if(i==2){
map<int,int>::iterator it=a.begin();
while(it->second<1)it++;
cout<<it->first<<endl;
}
else if(i==3){
map<int,int>::iterator it=a.begin();
while(it->second<1)it++;
(it->second)--;
}
}
return 0;
}