#include <stdio.h>
#include <string.h>

#define MAX 2000000
#define INFTY 1000000

int n, a[MAX+1];

void maxHeapify(int i){
  int m, k, largest, tmp;
  m = 2*i;
  k = 2*i+1;

  if(m <= n && a[m] > a[i])
    largest =m;
  else
    largest = i;
  if(k <= n && a[k] >  a[largest])
    largest = k;

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

int extract(){
  int maxv;
  if(n < 1)
    return -INFTY;
  maxv = a[1];
  a[1] = a[n--];
  maxHeapify(1);
  return maxv;
  
}

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

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

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

int main(){
  int key;
  char command[10];

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

