#include<stdio.h>
#define MAX 100000000
#define MINS -20000000

int heapsize=0;
int A[MAX],X[MAX];
int p(int heap){
  return heap/2;
}
int l(int heap){
  return heap*2;
}
int r(int heap){
  return (heap*2+1);
}

main(){
  
  int i=0,k=0,left,right,key;
  char com[20];
  
  while(1){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d",&key);
      maxHeapInsert(key);
    }else if(com[0] == 'e' && com[1] == 'x'){
      
      X[k]= heapExtractMax();
      
      k++;
    }else if(com[0] == 'e' && com[1] == 'n'){
      for(i = 0;i < k;i++)
	printf("%d\n",X[i]);
      break;
    }    
  }
  return 0;
}
int maxHeapify(i){
  int largest;
  int left = l(i);
  int right = r(i);
  if(left <= heapsize && A[i]< A[left]){
    largest = left;
  }else{
    largest = i;
  }
  if(right <= heapsize && A[right] > A[largest]){
    largest = right;
  }
  if(largest != i){
    int tmp;
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}
int buildMaxHeap(){
  int i;
  for(i = (heapsize/2); i >= 1;i--){
    maxHeapify(i);
  }
}
int maxHeapInsert(int key){
  heapsize = heapsize+1;
  A[heapsize] = MINS;
  heapIncreaseKey(heapsize,key);
}
int heapIncreaseKey(int i,int key){
  int tmp;
  if(key < A[i]){
    return;
  }
  A[i] = key;
  while(i > 1 && A[p(i)] < A[i]){
    tmp = A[i];
    A[i] = A[p(i)];
    A[p(i)] = tmp;
    i = p(i);
  }
}

int heapExtractMax(){
  int max;
  if(heapsize < 1){
    return;
  }
  max = A[1];
  A[1] = A[heapsize];
  heapsize = heapsize - 1;
  maxHeapify(1);
  return max;
}