// #pragma GCC optimize("O3,unroll-loops,fast-math")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int Nmax=2e5+5,inf=1e9,MOD=1e9+7;
int main() {
ifstream cin("heapuri.in");
ofstream cout("heapuri.out");
int n,cnt;
bitset<Nmax> del;
priority_queue<pii,vector<pii>,greater<pii>> pq;
cin>>n;
while (n--) {
int op;
cin>>op;
if (op==1) {
int x;
cin>>x;
cnt++;
pq.push({x,cnt});
}
else if (op==2) {
int x;
cin>>x;
del[x]=1;
}
else {
while (del[pq.top().se]) pq.pop();
cout<<pq.top().fi<<"\n";
}
}
return 0;
}