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

#define NIL 500009
 
int n,array[500010];

int getparent(int i){
    i /= 2;
    if(i < 1) return NIL;
     else return i;
}

int getleft(int i){
    i *= 2;
     if(i > n) return NIL;
    else return i;
}
 
int getright(int i){
    i = 2*i+1;
     if(i > n) return NIL;
    else return i;
}


void maxHeapify(int i){
  int l,r,largest,temp;
  
  l = getleft(i);
  r = getright(i);

  if(l <= n && array[l] > array[i])
    largest = l;
  else largest = i;
  

  if(r <= n && array[r] > array[largest])
    largest = r;
  
  if(largest != i){
    temp = array[i];
    array[i] = array[largest];
    array[largest] = temp;
    maxHeapify(largest);
  }
  
}

void buildMaxHeap(){
  int i;
  for(i=n/2; i>=1; i--){
    maxHeapify(i);
  }
}


void heapIncreaseKey(int i,int key){
  int temp;  
  if(key < array[i]){
    printf("error\n");
    exit(0);
  }
  array[i] = key;  
  while(i > 1 && array[getparent(i)] < array[i]){
    temp = array[i];
    array[i] = array[getparent(i)];
    array[getparent(i)] = temp;
      i = getparent(i);
  }
}


void maxHeapInsert(int key){
  n++;
  array[n] = NIL;
  heapIncreaseKey(n, key);
}

int heapExtractMax(){
  int max;
  
  if(n < 1){
    printf("error\n");
    exit(1);
  }
  max = array[1];
  array[1] = array[n];
  n--;
  maxHeapify(1);
  return max;
}


int main(){
  int i,parent,left,right,key;
  char com[20];
    
    scanf("%s",com);
 
    while(strcmp(com,"end") != 0 ){
      if(com[0] == 'i'){
      scanf("%d",&key);
      maxHeapInsert(key);
    } 
      if(com[1] == 'x'){
	printf("%d\n", heapExtractMax());
      }
  } 
  
  return 0;
}