#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
 
#define MAX 2000001
 
int heap[MAX];
int heap_size;
 
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, L, tmp;
  l=left(i);
  r=right(i);
  if(l <= heap_size && heap[l] > heap[i]){
   L=l;
  }
  else{
   L = i;
  }
 
  if(r <= heap_size && heap[r] > heap[L]){
   L=r;
  }
  if(L != i){
    tmp=heap[i];
    heap[i] = heap[L];
    heap[L] = tmp;
    maxHeapify(L);
  }
}
 
void buildMaxHeap(){
  int i;
  for(i = heap_size/2; i > 0; i--){
    maxHeapify(i);
  }
}
 
void heapIncreaseKey(int i, int key){
  int tmp;
 
  heap[i] = key;
 
  while(i > 1 && heap[parent(i)] < heap[i]){
    tmp = heap[i];
    heap[i] = heap[parent(i)];
    heap[parent(i)] = tmp;
    i = parent(i);
  }
}
 
void maxHeapInsert(int key){
  heap_size = heap_size + 1;
  heap[heap_size] = INT_MIN;
  heapIncreaseKey(heap_size, key);
}
 
int heapExtractMax(){
  int max = heap[1];
 
  heap[1] = heap[heap_size];
  heap_size = heap_size - 1;
  maxHeapify(1);
 
  return max;
}
 
int main(void){
  int i,key;
  char com[MAX-1];
 
  for(i = 1; i <= MAX-1; i++){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d",&key);
      maxHeapInsert(key);
    }else if(com[0] == 'e' && com[1] == 'x'){
      printf("%d\n",heapExtractMax());
    }else if(com[0] == 'e' && com[1] == 'heap_size'){
      break;
    }
  }
 
  return 0;
}