#include <stdio.h>
#include <string.h>
#define N 2000001
#define NIL -1000
 
int num;
int A[N];
 
int parent(int i){
  return i/2;
}
 
int left(int i){
  return 2*i;
}
 
int right(int i){
  return 2*i+1;
}
 
void heapIncreaseKey(int i, int key){
  int temp;
  if(key < A[i]){
    return;
  }
  A[i] = key;
  while(i > 1 && A[parent(i)] < A[i]){
    temp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = temp;
    i = parent(i);
  }
}
 
void maxHeapInsert(int key){
    num = num + 1;
    A[num] = NIL;
    heapIncreaseKey(num, key);
}
 
 
void maxHeapify(int i){
  int largest=0,temp;
  int l,r;
  l = left(i);
  r = right(i);
  if(l <= num && A[l] > A[i]){
    largest = l;
  }
  else
    largest = i;
  if(r <= num && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
}
 
 
int heapExtractMax(){
  int max;
  if(num < 1){
    return 0;
  }
  max = A[1];
  A[1] = A[num];
  num = num-1;
  maxHeapify(1);
  return max;
} 
 
main(){
  int k;
  char b[12];
  while(1){
    scanf("%s",b);
    if(b[0] == 'i'){
      scanf("%d",&k);
      maxHeapInsert(k);
    }
    else if(b[0] == 'e' && strcmp(b,"extract") == 0){
      printf("%d\n",heapExtractMax());
     }
    else
      break;
       }
  return 0;
}
