#include<stdio.h>
int R=1,C=1,H[1000010]={0};
int N[1000010]={-1000};
//??????????????\??????
void prih(){
  int i,j=1;printf("\n");
  for(i=1;i<C;i++){
    if(i==1<<j){
      printf("\n");
      j++;
    }
    printf("%d ",N[H[i]]);
  }
  printf("\n\n");
}
int hyouka(int a,int b){//printf("%d %d\n",a,b);
  if(b==0)return 0;
  if(C<b)return 1;
  if(C<a)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
void hin(int a){
  int i=C++;
  H[0]=R;
  for(N[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]=hyouka(i*2,i*2+1)?H[j=i*2]:H[j=i*2+1];
  H[i/2]=k;//prih();
  return rt;
}/*
//???????????????????°???????????????????
int hout(){
  int rt=H[1],nt=1,i=0,k=H[--C];
  while(nt-i){
    H[i=nt]=k;
    if(i*2  <C&&N[  k  ]>N[H[i*2  ]])H[i]=H[nt=i*2  ];
    if(i*2+1<C&&N[H[nt]]>N[H[i*2+1]])H[i]=H[nt=i*2+1];
  }
  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;
}