#include <stdio.h>
#include <string.h>
#define MAX 2000000
#define INFTY 30

int h, a[MAX+1];

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

int main(){
  int k;
  char c[7];

  while(1){
    scanf("%s", c);
    if(strcmp(c, "end") == 0) break;
    if(strcmp(c, "insert") == 0){
      scanf("%d", &k);
      insert(k);
    }
    else printf("%d\n", extract());
  }
  return 0;
}

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

  l = 2 * i;
  r = 2 * i + 1;
  if(l <= h && a[l] > a[i]){
    largest = l;
  }
  else largest = i;
  if(r <= h && a[r] > a[largest]){
    largest = r;
  }
  if(largest != i){
    b = a[i];
    a[i] = a[largest];
    a[largest] = b;
    maxHeapify(largest);
  }
}

int extract(){
  int maxv;

  if(h < 1) return -INFTY;
  maxv = a[1];
  a[1] = a[h--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key){
  int b;

  if(key < a[i]) return;
  a[i] = key;
  while(i > 1 && a[i/2] < a[i]){
    b = a[i];
    a[i] = a[i/2];
    a[i/2] = b;
    i = i / 2;
  }
}

void insert(int key){
  h++;
  a[h] = -INFTY;
  increaseKey(h, key);
}