#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
using namespace std;
vector<long long> a;
int main() {
int n;cin >> n;
while (n--) {
int b;cin >> b;int c;
if (b == 1) {
int x = 1;cin >> c;
for (int i = 0;i < a.size();i++) {
if (c > a[i])x++;
}
cout << x;
}
else if (b == 2) {
int x;cin >> x;
cout << a[x-1];
}
else if (b == 3) {
int x,y=0;cin >> x;
for (int i = 0;i < a.size();i++) {
if (x < a[i]) {
if (x != a[i - 1] && i >= 1)
cout << a[i - 1];
else if (x==a[i-1]&&i >= 2)
cout << a[i - 2];
else cout << "−2147483647";
}
}
}
else if (b == 4) {
int x, y = 0;cin >> x;
for (int i = 0;i < a.size();i++) {
if (x > a[i]) {
if (x != a[i + 1] && i+1<a.size())
cout << a[i + 1];
else if (x == a[i + 1] && i+2<a.size())
cout << a[i + 2];
else cout << "2147483647";
}
}
}
else if (b == 5) {
int x;cin >> x;
if(find(a.begin(),a.end(),x)==a.end())
a.push_back(x);
sort(a.begin(), a.end());
}
}
return 0;
}