#include <stdio.h>
#include <stdlib.h>
 
void MaxHeap(int *,int);

int main(int argc,char *argv[]) {
    int *hp, key, index, half, tmp;
    char cmd[20];
 
    hp = malloc(sizeof(int) * 2000001);
    hp[0] = 1;
    
    while (1) {
        scanf("%s %d ", cmd, &key);
        if (cmd[0] == 'i') {
            hp[0]++;
            index = hp[0];
            hp[index] = key;
 
            half = index / 2;
            while (index > 1 && hp[half] < hp[index]) {
                tmp = hp[index];
                hp[index] = hp[half];
                hp[half] = tmp;
                index /= 2;
                half = index / 2;
            }
        } else if (cmd[1] == 'x') {
            printf("%d\n", hp[1]);
            hp[1] = hp[hp[0]];
            hp[0]--;
            MaxHeap(hp, 1);
        } else {
	  
            return 0;
        }
    }
    
    return 0;
}
void MaxHeap(int *hp, int a) {
  int hsize, l, r, largest, tmp;
  
  hsize = hp[0];
  l = 2*a;
  r = 2*a + 1;
  if (l <= hsize && hp[l] > hp[a]) 
      largest = l;
  else 
      largest = a;
  if (r <= hsize && hp[r] > hp[largest]) 
      largest = r;
  if (largest != a) 
    {
      tmp = hp[a];
      hp[a] = hp[largest];
      hp[largest] = tmp;
      MaxHeap(hp, largest);
    }
}

