#include<stdio.h>
int R=1,C=1,H[2000010]={0};
int N[2000010]={-1000};
int hyouka(int a,int b){//printf("%d %d\n",a,b);
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;//prih();//printf("%d\n",i);
}
int hout(){
  int rt=H[1],i=0,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[i/2]=k;
  return rt;
}
int main(){
  int a;
  char s[100];
  while(scanf("%s",s),s[2]-'d'){//prih();
    if(s[2]=='s'){
      scanf("%d",&a);
      hin(a);
    }
    else printf("%d\n",N[hout()]);
  }//prih();
  return 0;
}