#include <cstdio>
#include <queue>
using namespace std;
const int NMAX = 200010;
int N, K, Type, X;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > Q;
bool Out[NMAX];
int main()
{
freopen("heapuri.in", "r", stdin);
freopen("heapuri.out", "w", stdout);
scanf("%i", &N);
for(int i = 1; i <= N; ++ i)
{
scanf("%i", &Type);
if(Type == 1)
{
scanf("%i", &X);
Q.push(make_pair(X, ++K));
}else if(Type == 2)
{
scanf("%i", &X);
Out[X] = 1;
}else
{
while(Out[ Q.top().second ]) Q.pop();
printf("%i\n", Q.top().first);
}
}
}