#include <stdio.h>
#define IMF 100000

void maxHeapify(int);
void buildMaxHeap();
void maxHeapInsert(int);
void heapIncreaseKey(int,int);
int  heapExtractMax();
int S[2000000];
int size=0;

int main(){
  int i,n,max;
  char com[20];


  while(1){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d",&n);
      maxHeapInsert(n);
    }
    if(com[0] == 'e' && com[1] == 'x'){
      max = heapExtractMax();
      printf("%d\n",max);
    }
    if(com[0] == 'e' && com[1] == 'n'){
      break;
    }
  }
  return 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,hozon;
  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){
    hozon = S[i];
    S[i] = S[largest];
    S[largest] = hozon;
    maxHeapify(largest);
  }
  
}


void maxHeapInsert(int key){
  size++;
  S[size] = -IMF;
  heapIncreaseKey(size,key);
}

void heapIncreaseKey(int size,int key){
  int hozon;
  if(key < S[size]){
    printf("new hey is smaller than current key");
  }
  S[size] = key;
  while ( size > 1  && S[parent(size)]<S[size]){
    hozon = S[size];
    S[size] = S[parent(size)];
    S[parent(size)] = hozon;
    size = parent(size);
  }
}

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

