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

#define MAX_HEAP_SIZE 2000000
#define COMMAND_LEN 24
#define INF_POS 2000000001
#define INF_NEG -2000000001

int heap[MAX_HEAP_SIZE + 1];

int hsize = 0;

int left(int id);

int right(int id);

int parent(int id);

void maxHeapify(int rootId);
void buildMaxHeap(void);

int heapMaximum();
int heapExtractMax();
void heapIncreaseKey(int id, int key);
void maxHeapInsert(int key);

int main(){
  int n;
  char strBuf[COMMAND_LEN];

  while(1){
    scanf("%s", strBuf);

    if(strcmp("end", strBuf) == 0){
      break;
    }
    else if(strcmp("insert", strBuf) == 0){
      scanf("%d", &n);
      maxHeapInsert(n);
    }
    else if(strcmp("extract", strBuf) == 0){
      printf("%d\n", heapExtractMax());
    }
    else {
      printf("ERROR: INVALID COMMAND\n");
      exit(1);
    }
  }
  
  return 0;
}

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

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

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

void maxHeapify(int rootId){
  int l = left(rootId);
  int r = right(rootId);
  int largest;
  
  //左の子、自分、右の子で値が最大のノードを選ぶ
  if(l <= hsize && heap[l] > heap[rootId]){
    largest = l;
  }
  else {
    largest = rootId;
  }

  if(r <= hsize && heap[r] > heap[largest]){
    largest = r;
  }

  int tmp;
  if(largest != rootId){ //rootIdの子の方が値が大きいとき
    tmp = heap[rootId];
    heap[rootId] = heap[largest];
    heap[largest] = tmp;
    maxHeapify(largest);
  }
}

void buildMaxHeap(){
  for(int i = hsize/2 ; i >= 1; i--){
    maxHeapify(i);
  }
}
    
int heapMaximum(){
  return heap[1];
}

int heapExtractMax(){
  if(hsize < 1){
    printf("ERROR: HEAP UNDER FLOW\n");
    exit(1);
  }

  int max = heap[1];
  heap[1] = heap[hsize];
  hsize--;
  maxHeapify(1);
  return max;
}
    
void heapIncreaseKey(int id, int key){
  if(key < heap[id]){
    printf("ERROR: KEY VALUE IS SMALLER");
    exit(1);
  }
  heap[id] = key;
  while(id > 1 && heap[parent(id)] < heap[id]){
    int tmp = heap[id];
    heap[id] = heap[parent(id)];
    heap[parent(id)] = tmp;
    id = parent(id);
  }
}

void maxHeapInsert(int key){
  hsize++;
  heap[hsize] = INF_NEG;
  heapIncreaseKey(hsize, key);
}

