#include<iostream>
using namespace std;
#include<queue>
struct node
{
int num;
friend bool operator < (node a,node b)
{
return a.num>b.num;
}
} a[100005];
int main()
{
int n,k;
int x;
char cha;
priority_queue<node> ms;
while(cin>>n>>k)
{
int cout=0;
while(!ms.empty())
ms.pop();
while(n--)
{
getchar();
scanf("%c",&cha);
if(cha=='I')
{
scanf("%d",&x);
cout++;
a[cout].num=x;
ms.push(a[cout]);
if(cout>k)
ms.pop();
}
else
printf("%d\n",(ms.top()).num);
}
}
return 0;
}
using namespace std;
#include<queue>
struct node
{
int num;
friend bool operator < (node a,node b)
{
return a.num>b.num;
}
} a[100005];
int main()
{
int n,k;
int x;
char cha;
priority_queue<node> ms;
while(cin>>n>>k)
{
int cout=0;
while(!ms.empty())
ms.pop();
while(n--)
{
getchar();
scanf("%c",&cha);
if(cha=='I')
{
scanf("%d",&x);
cout++;
a[cout].num=x;
ms.push(a[cout]);
if(cout>k)
ms.pop();
}
else
printf("%d\n",(ms.top()).num);
}
}
return 0;
}