#include <stdio.h>
#include <string.h>
#define N 2000001
#define NIL -1000

int n;
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 tmp;
  if(key < a[i]){
    return;
  }
  a[i] = key;
  while(i > 1 && a[parent(i)] < a[i]){
    tmp = a[i];
    a[i] = a[parent(i)];
    a[parent(i)] = tmp;
    i = parent(i);
  }
}

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


void maxHeapify(int i){
  int largest=0,tmp;
  int l,r;
  l = left(i);
  r = right(i);
  if(l <= n && a[l] > a[i]){
    largest = l;
  }
  else
    largest = i;
  if(r <= n && a[r] > a[largest]){
    largest = r;
  }
  if(largest != i){
    tmp = a[i];
    a[i] = a[largest];
    a[largest] = tmp;
    maxHeapify(largest);
  }
}


int heapExtractMax(){
  int max;
  if(n < 1){
    return 0;
  }
  max = a[1];
  a[1] = a[n];
  n = n-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;
}