#include <iostream>
#include <fstream>
#include <vector>
#include <set>
using namespace std;
int main() {
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int n, a, x;
vector<int> v;
set<int> s;
fin >> n;
for (int i = 0; i < n; i++) {
fin >> a;
if (a == 1) {
fin >> x;
v.push_back(x);
s.insert(x);
}
else if (a == 2) {
fin >> x;
int index = x - 1;
if (index >= 0 && index < v.size()) {
int value = v[index];
auto it = s.find(value);
if (it != s.end()) {
s.erase(it);
}
}
}
else if (a == 3) {
if (!s.empty()) {
fout << *s.begin() << endl;
}
}
}
fin.close();
fout.close();
return 0;
}