#include <fstream>
#include <vector>
#include <iterator>
void push(std::vector<int>& v, int val) {
int i = 0;
for (; i < v.size() && v[i] < val; i++);
v.insert(v.begin() + i, val);
}
void remove(std::vector<int>& v, int val) {
std::vector<int>::iterator found = std::find(v.begin(), v.end(), val);
if (found != v.end())
v.erase(found);
}
int main() {
std::ifstream f("heapuri.in");
std::ofstream g("heapuri.out");
std::vector<int> v, ord;
int command, n, tmp;
f >> n;
for (int i = 0; i < n; i++) {
f >> command;
if (command == 1) {
f >> tmp;
push(v, tmp);
ord.push_back(tmp);
}
if (command == 2) {
f >> tmp;
remove(v, ord[tmp - 1]);
}
if (command == 3) {
g << v[0] << "\n";
}
}
}