#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int n, op, x,cnt=1,a[10005];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> op >> x;
if (op == 1) cout << lower_bound(a + 1, a + cnt, x) - a<<endl;
if (op == 2) cout << a[x] << endl;
if (op == 3) {
int tmp = lower_bound(a + 1, a + cnt, x) - a;
if (tmp == 1)cout << -2147483647 << endl;
else cout << a[tmp - 1] << endl;
}
if (op == 4) {
int tmp = upper_bound(a + 1, a + cnt, x) - a;
if (tmp == cnt)cout << -2147483647 << endl;
else cout << a[tmp ] << endl;
}
if (op == 5) {
a[cnt] = x;
cnt++;
sort(a + 1, a + cnt);
}
}
return 0;
}