#include<stdio.h>
#include<stdlib.h>
#define MAX 200000


void swap(int x,int y,int S[]){
int temp;
temp=S[x];
S[x]=S[y];
S[y]=temp;
return;
}


void sortA(int S[],int last){

while(last!=1){
 if(S[last]>S[last/2]){swap(last,last/2,S);last=last/2;}
 else{break;}
}

return;
}


void sortB(int S[],int last){
int i=1;

while(S[2*i]!=-1&&S[2*i+1]!=-1){

 if(S[i]>S[2*i]&&S[i]>S[2*i+1]){break;}

 else if(S[i]>S[2*i]&&S[i]<S[2*i+1]){swap(i,2*i+1,S);i=2*i+1;}

 else if(S[i]<S[2*i]&&S[i]>S[2*i+1]){swap(i,2*i,S);i=2*i;}

 else{ if(S[2*i]>S[2*i+1]){swap(i,2*i,S);i=2*i;}
       else{swap(i,2*i+1,S);i=2*i+1;}  }


}/*while end*/


return;
}

int main(){
int i,n,x;
int a=0;
int last=0;
int S[MAX];
char com[8];



for(i=0;i<MAX;i++)S[i]=-1;



while(a<1){
scanf("%s",com);

 switch(com[2]){
  case 's':scanf("%d",&x);
           last++;
           S[last]=x;
           sortA(S,last);
           break;
  case 't':printf("%d\n",S[1]);
           S[1]=S[last];
           S[last]=-1;
           last--;
           sortB(S,last);
           break;
  case 'd':a++;
           break;
 }/*switch end*/

}/*while end*/



return 0;
}
