#include<stdio.h>
#define MAX 2000001
#define LEN  8
#define INFTY -1

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

int h = 0;
int a[MAX];

int main(){
  char com[LEN];
  int key;

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

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

void heapIncreaseKey(int key, int i){
  int parent = i / 2;
  int v;
  if(key < a[h]) return;
  a[h] = key;
  while(i > 1 && a[parent] < a[i]){
    //a[i]とa[parent]を交換
    v = a[i];
    a[i] = a[parent];
    a[parent] = v;
    //親子関係更新
    i = parent;
    parent = i / 2;
  }
}

int extract(){
  int max;
  if(h < 1) return 0;
  max = a[1];
  a[1] = a[h];
  h--;
  maxHeapify(1);
  return max;
}

void maxHeapify(int i){
  int l, r; //lは左の子のノード番号, rは右の子のノード番号
  int largest; //自分と左の子と右の子でkeyが最大のノードの番号
  int v;
  
  l = 2 * i;
  r = 2 * i + 1;

  //keyが最大のノードを選ぶ
  if(l <= h && a[l] > a[i]) largest = l;
  else largest = i;
  if(r <= h && a[r] > a[largest]) largest = r;

  //iのこの方が大きい時a[i]とa[largest]を交換
  if(largest != i){
    v = a[i];
    a[i] = a[largest];
    a[largest] = v;
    maxHeapify(largest);
  }
}

