#include<bits/stdc++.h>
using namespace std;
int s[10010];
int p=1;
inline int read()
{
char ch;
register int ans=0;
ch=getchar();
while(ch>='0'&&ch<='9')
{
ans=(ans<<3)+(ans<<1)+(ch^48);
ch=getchar();
}
return ans;
}
int main()
{
//freopen("w.txt","w",stdout);
int tiao=read();
for(int jakdj=1;jakdj<=tiao;jakdj++)
{
int a=read(),b=read();
switch(a)
{
case 1:
{
for(int i=1;i<=p;i++)
if(s[i]==b) cout<<i<<endl;
break;
}
case 2:
{
cout<<s[b]<<endl;
break;
}
case 3:
{
int tmp=0;
for(int i=1;i<=p;i++)
if(s[i]==b) tmp=i;
if(tmp-1!=0) cout<<s[tmp-1]<<endl;
else cout<<-2147483647<<endl;
break;
}
case 4:
{
int tmp=0;
for(int i=1;i<=p;i++)
if(s[i]==b) tmp=i;
if(tmp+1<=p) cout<<s[tmp+1]<<endl;
else cout<<2147483647<<endl;
break;
}
case 5:
{
s[p]=b;
p++;
for(int i=p-1;i>1;i--)
if(s[i]<s[i-1]) swap(s[i],s[i-1]);/*
for(int i=0;i<=p;i++) cout<<s[i]<<' ';
cout<<endl;*/
break;
}
default: break;
}
}
return 0;
}