#include <bits/stdc++.h>
using namespace std;
const int N = 1e+6;
int n, idx = 0, q[N];
int main(){
cin >> n;
while(n --){
int x;
cin >> x;
if(x == 1) {
int y;
cin >> y;
q[idx ++ ] = y;
}
else if(x == 2){
sort(q, q + idx);
cout << q[0] << endl;
}
else{
sort(q, q + idx, greater<int>());
idx --;
}
}
}