#include <bits/stdc++.h>
#define int long long
using namespace std;
int q;
multiset <int> st;
signed main(){
cin >> q;
while (q --){
int AC, x, k;
cin >> AC;
if (AC == 1){
cin >> x;
st.insert(x);
}
if (AC == 2){
cin >> x >> k;
auto n = upper_bound (st.begin(),st.end(),x);
while (n != st.begin() && k != 0){
k --;
-- n;
}
if (k > 0) cout << -1 << endl;
else cout << *n << endl;
}
if (AC == 3){
cin >> x >> k;
auto n = lower_bound (st.begin(),st.end(),x);
while (n != st.end() && k > 1){
k --;
++ n;
}
if (n == st.end()) cout << -1 << endl;
else cout << *n << endl;
}
}
}