#include <stdio.h>

int S[2000000], n = 0;

void maxHeapify(int i){
  int l, r, largest, a;

  l = i * 2;
  r = i * 2 + 1;

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

  if(r <= n && S[r] > S[largest])
    largest = r;

  if(largest != i){
    a = S[i];
    S[i] =  S[largest];
    S[largest] = a;
    maxHeapify(largest);
  }
}

void insert(int k){
  S[n] = k;
  n++;
}
int extractMax(){
  int i, e;
  for(i = n / 2; i >= 1; i--) maxHeapify(i);
  e = S[0];
  for(i = 0; i < n; i++){
    S[i] = S[i + 1];
  }
    n--;

  return e;
}
int main(){
  int key;
  char a[10];

  while(1){
    scanf("%s", a);
    if(a[0] == 'e' && a[1] == 'n') break;
    if(a[0] == 'i') {
      scanf("%d", &key);
      insert(key);
    }
    else printf("%d\n", extractMax());
  }

  return 0;
}