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

typedef struct cell{
 int id;
 struct cell *next;
}cell;


cell* makecell(int x){
cell *new=malloc(sizeof(cell));
new->id=x;
new->next=NULL;

return new;
}


void insert(cell **p,cell *new){
cell *q;
if((*p)==NULL){(*p)=new;return;}
else{
  if((*p)->id < (new)->id){
     (new)->next=(*p);
     (*p)=(new);return;
  }
  else{insert(&((*p)->next),new);}
 
}


return;
}


int main(){
int i,n,x;
int a=0;
char com[8];
cell *root=NULL;
cell *new;

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

 switch(com[2]){
  case 's':scanf("%d",&x);
           new=makecell(x);
           insert(&root,new);
           break;
  case 't':printf("%d\n",root->id);
           root=root->next;
           break;
  case 'd':a++;
           break;
 }/*switch end*/

}/*while end*/



return 0;
}
