#include <stdio.h>
#include <string.h>
#define MAX 2000001
int left(int i);
int right(int i);
int parent(int i);
void maxHeapify(int i);
int extractMax(void);
void increaseKey(int i, int key);
void maxHeapInsert(int key);
int heap[MAX];
int size;

int left(int i){
  return 2*i;
}
  
int right(int i){
  return 2*i+1;
}
 
int parent(int i){
  return i/2;
}
 
void maxHeapify(int i){
  int l, r, x, largest;
  l = left(i);
  r = right(i);
  if( l <= size && heap[l] > heap[i] ){
    largest = l;
  }
  else{ 
    largest = i;
  }
  if( r <= size && heap[r] > heap[largest] ){
    largest = r;
  }
  if( largest != i ){
    x = heap[i];
    heap[i] = heap[largest];
    heap[largest] = x;  
    maxHeapify(largest);
  }
}
 
int extractMax(void){
  int max;
  max = heap[1];
  heap[1] = heap[size];
  size = size - 1;
  maxHeapify(1);
  return max;
}
 
void increaseKey(int i, int key){
  int x;
    heap[i] = key; 
    while( i > 1 && heap[parent(i)] < heap[i] ){
      x = heap[i];
      heap[i] = heap[parent(i)];
      heap[parent(i)] = x;
      i = parent(i);
    }  
}
 
void maxHeapInsert(int key){
  size = size + 1;
  heap[size] = -1;
  increaseKey(size, key); 
}
 
int main(){
  int i, key, max;
  char command[10];  
  while(1){
    scanf("%s", command);
    if( strcmp("end", command) == 0 ) break; 
    else if( strcmp("extract", command) == 0 ){
      max = extractMax();
      printf("%d\n", max);
    }
    else if( strcmp("insert", command) == 0 ){
      scanf("%d", &key);
      maxHeapInsert(key);
    }
    else continue;
  }
  return 0;
}

