#include<stdio.h>
#define MAX 2000000

void maxHeapify(int);
void swap(int,int);
void insert(int);
int extract(void);

int array[MAX],key_count=0;
  
int main(){
  int i,key;
  char command[10];
  while(1){
    scanf("%s",command);
    if(command[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(command[0]=='e' && command[1] =='n')break;
    else printf("%d\n",extract());
  }
  return 0;
}

void insert(int key){
  int i=key_count;
  array[key_count++]=key;
  while(i > 0 && array[(i-1)/2] < array[i]){
    swap((i-1)/2,i);
    i = (i-1)/2;
  }
}

int extract(){
  int return_number;
  return_number = array[0];
  array[0] = array[--key_count];
  maxHeapify(0);
  return return_number;
}
  
void maxHeapify(int i){
  int l,r,max;
 
  l = i*2+1;
  r = (i+1)*2;
  if(l < key_count && array[l] > array[i])max = l;
  else max = i;
  if(r < key_count && array[r] > array[max])max = r;
  if(max != i){
    swap(i,max);
    maxHeapify(max);
  }  
}

void swap(int i,int j){
  int tmp;
  tmp = array[i];
  array[i] = array[j];
  array[j] = tmp;
}

