#include <bits/stdc++.h>
using namespace std;
ifstream fin ("heapuri.in");
ofstream fout ("heapuri.out");
priority_queue <pair <int, int>, vector <pair<int, int>>, greater <pair<int, int>>> pq;
int n, x, sterge[200005], q, ind;
int main()
{
fin >> n;
for (int i = 1; i <= n; i++) {
fin >> q;
if (q == 1) {
fin >> x;
ind++;
pq.push({x, ind});
}
else if (q == 2) {
fin >> x;
sterge[x] = 1;
}
else if (q == 3) {
while (!pq.empty() && sterge[pq.top().second]) {
pq.pop();
}
fout << pq.top().first << '\n';
}
}
return 0;
}