#include<stdio.h>
#include<string.h> 
int heap[500010];
int datasum; 
void maxHeapify( int,int);
void buildMaxHeap(int);
int extractvalue();
 
int main(){
 
  int i,j,sumnode,inputdata;
  char command[10];

  while(1){

    scanf("%s",command);
 
  if((strcmp(command,"end")) == 0){

      break;

    }

    else if((strcmp(command,"insert")) == 0){

      datasum = datasum + 1;

      scanf("%d",&heap[datasum]);

      buildMaxHeap(datasum);

    }

    else if((strcmp(command,"extract")) == 0){

      printf("%d\n",extractvalue());

    }

    
  }
    
  return 0;
    
}
 
void buildMaxHeap(int sumnode){
 
  int i;
 
  for(i = sumnode/2; i >=1 ; i--){
 
    maxHeapify(i,sumnode);
 
  }
 
}
 
void maxHeapify(int i ,int sumnode){
 
  int left,right,largest,swap;
 
  left = i *2;
  right = i *2 +1;
 
  if(left <= sumnode && heap[left] > heap[i]){
 
    largest = left;
 
  }
 
  else{
 
    largest = i;
 
  }
 
 
  if(right <= sumnode && heap[right] > heap[largest]){
 
    largest = right;
 
  }
 
 
  if(largest != i){
 
    swap = heap[i];
 
    heap[i] = heap[largest];
 
    heap[largest] = swap;
 
    maxHeapify(largest,sumnode);
 
  }
 
}

int extractvalue(){

  int value;

  value = heap[1];

  heap[1] = heap[datasum];

  datasum = datasum - 1;

  buildMaxHeap(1);

  return value;

}