#include <bits/stdc++.h>
#define NMAX 200005
#define INF 10000000001
using namespace std;
ifstream fin("heapuri.in");
ofstream fout("heapuri.out");
int n, op, nr, heap[NMAX + 3], z;
int a[NMAX + 3], b[NMAX + 3], i;
void schimba(int index1, int index2)
{
swap(heap[index1], heap[index2]);
a[b[index1]] = index2;
a[b[index2]] = index1;
swap(b[index1], b[index2]);
}
void Add()
{
heap[++z] = nr;
++i;
a[i] = z;
b[z] = i;
int index = z;
while (heap[index] < heap[index / 2] && index > 1)
{
schimba(index, index / 2);
index = index / 2;
}
}
void Del()
{
int index = a[nr];
schimba(index, z);
heap[z] = INF;
--z;
while ((heap[index] > heap[index * 2] || heap[index] > heap[index * 2 + 1]) && index * 2 <= z)
{
if (heap[index * 2 + 1] < heap[index * 2])
{
schimba(index, index * 2 + 1);
index = index * 2 + 1;
}
else
{
schimba(index, index * 2);
index = index * 2;
}
}
}
int main()
{
fin >> n;
for (int i = 0; i <= NMAX; ++i)
{
heap[i] = INF;
}
while (n--)
{
fin >> op;
if (op == 1)
{
fin >> nr;
Add();
}
else if (op == 2)
{
fin >> nr;
Del();
}
else
{
fout << heap[1] << "\n";
}
}
return 0;
}