#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 2000000
#define Gard -1

void InsertHeap(int );
void IncreHeap(int,int);
int ExtractHeap();
void MaxHeap(int,int);

int element,Prio[N];
int heapnum;

int main(){
  int count=0;
  int result=0;
  char order[15];
  char *End="end";
  char *Ext="extract";

  while(1){
    scanf("%s",order);

    count++;
    
    if(count==N){
      break;
    }
    
    else if(strcmp(order,End)==0){
      break;
    }


    if(order[0]=='i'){
      scanf("%d",&heapnum);
      InsertHeap(heapnum);
    }

    else if(strcmp(order,Ext)==0){
      result=ExtractHeap();

      if(result==Gard){
	continue;
      }

      else{
	printf("%d\n",result);
      }
      
    }
  }
  
  return 0;
}

void InsertHeap(int heapnum){
  
  element++;

  Prio[element]=Gard;

  IncreHeap(heapnum,element);
 
}

void IncreHeap(int heapnum ,int element){
  int temp;
  
  if(heapnum<Prio[element]){
    return;
  }

  else{
    Prio[element]=heapnum;

    while((element>1)  && (Prio[element/2]<Prio[element])){

      temp=Prio[element];
      Prio[element]=Prio[element/2];
      Prio[element/2]=temp;

      element=element/2;
      
    }
  }
  
}

int ExtractHeap(){
  int MaxH=0;

  if(element<1){
    return Gard;
  }

  else{
    MaxH=Prio[1];
    Prio[1]=Prio[element];
    element--;
    MaxHeap(1,element);
    return MaxH;
  }
}

void MaxHeap(int judge,int element){
  int left,right,temp;
  int Hscale;

  left=2*judge;
  right=2*judge+1;

  if((element>=left) && (Prio[judge]<Prio[left])){
    Hscale=left;
  }

  else{
    Hscale=judge;
  }

  if((element>=right) && (Prio[Hscale]<Prio[right])){
    Hscale=right;
  }

  if(judge!=Hscale){
    temp=Prio[judge];
    Prio[judge]=Prio[Hscale];
    Prio[Hscale]=temp;
    MaxHeap(Hscale,element);
  }
}

