#include <iostream>
#include <fstream>
#include <set>
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
const int MAXN = 200005;
int val_of_id[MAXN];
int main() {
int n;
fin>>n;
set<pair<int, int>> s;
int insert_count = 0;
for (int i = 0; i < n; ++i) {
int type;
fin >> type;
if (type == 1) {
int x;
fin >> x;
insert_count++;
val_of_id[insert_count] = x;
s.insert({x, insert_count});
}
else if (type == 2) {
int x;
fin >> x;
s.erase({val_of_id[x], x});
}
else if (type == 3) {
fout << s.begin()->first << "\n";
}
}
return 0;
}