#include <stdio.h>
#define MAX 500001


int A[MAX];
char Ch[100];
int heap_size=0;


void maxheapify(int j){
  int largest,leftH,rightH;
    int tmp;
 

    leftH = Left(j);


    rightH = Right(j);

  if(leftH <= heap_size && A[leftH] > A[j]){
    largest=leftH;
  }

  else {
    largest=j;
  }

  if(rightH <= heap_size && A[rightH] > A[largest]){
   
 largest=rightH;

  }
  if(largest != j){

    tmp=A[j];

     A[j]=A[largest];
    A[largest]= tmp;


    maxheapify(largest);
  }
}
 




void heapIncreaseKey(int,int);
 
void maxHeapInsert(int key){
  heap_size = heap_size+1;
  A[heap_size]=-1;
  heapIncreaseKey(heap_size,key);
}
 
void heapIncreaseKey(int i,int key){
  int t;
  if(key < A[i]){
    return ;
  }
  A[i]=key;
  while(i > 1 && A[Parent(i)]<A[i]){
   
    t=A[i];
    A[i]=A[Parent(i)];
    A[Parent(i)]=t;
    i = Parent(i);
  }
}
 
int heapExtractMax(){
  int m;
  if(heap_size < 1){
    return -1;
  }
  m = A[1];
  
  A[1]=A[heap_size];
  heap_size = heap_size -1;
  maxHeapify(1);
  return m;
}
 


int Parent(int i){

  return(i/2);
}


int Left(int i){

  return 2*i;
}

int Right(int i){

  return 2*i+1;
}

int main(){

  int i;


while(1){
    scanf("%s",Ch);
    if(Ch[0]=='i'){

      scanf("%d",&i);

      maxHeapInsert(i);

    } 
    else if(Ch[2]=='d'){
      break;
    } 

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