#include <stdio.h>
#include <string.h>
#define MAX 2000001
#define INF 100000001

int S[MAX],size = 0;

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

void maxHeapify(int i){
  int l,r,largest,kari;
  l = left(i);
  r = right(i);
  if(l <= size && S[l] > S[i]) largest = l;
  else largest = i;
  if(r <= size && S[r] > S[largest]) largest = r; 

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

void increaseKey(int i, int key){
  int kari;
  if(key < S[i]) printf("new key is smaller than current key\n");
  S[i] = key;
  while(i>1 && S[parent(i)] < S[i]){
    kari = S[i];
  S[i] = S[parent(i)];
  S[parent(i)] = kari;
  i = parent(i);
  }
}

void insert(int key){
  size += 1;
  S[size] = -INF;
  increaseKey(size,key);
}

int extractMax(){
  int max;
  if(size < 1) printf("heap underflow\n");
  max = S[1];
  S[1] = S[size];
  size--;
  maxHeapify(1);
  return max;
}

int main(){
  int i,key;
  char order[10];
  while(1){
    scanf("%s",order);
    if(strcmp(order,"insert") == 0){
      scanf("%d",&key);
      insert(key);
    }
    else if(strcmp(order,"extract") == 0){
      printf("%d\n",extractMax());
    }
    else if(strcmp(order,"end") == 0){
      break;
    }
  }

  return 0;

}