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

#define ARRAY_SIZE 2000001

int parent(int pos) {
  if( pos != 1 ) {
    return (int)pos/2;
  }else {
    return -1;
  }
}


int left(int pos, int len) {
  if( pos*2 <= len ) {
    return pos*2;
  }else {
    return -1;
  }
}


int right(int pos, int len) {
  if( pos*2+1 <= len ) {
    return pos*2+1;
  }else {
    return -1;
  }
}


void swap(int* a, int* b) {
  int tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;

}


void maxHeapify(int* heap, int pos, int heapSize) {

  int l, r;
  int largest;

  l = left(pos, heapSize);
  r = right(pos, heapSize);

  //左、右、自身のうち最大のノード
  if( l != -1 && heap[l] > heap[pos] ) {
    largest = l;
  }
  else {
    largest = pos;
  }
  if( r != -1 && heap[r] > heap[largest] ) {
    largest = r;
  }


  if( largest != pos ) {
    swap(&heap[pos], &heap[largest]);
    maxHeapify(heap, largest, heapSize);
  }

}


void changeUp(int* heap, int pos) {
  /*
   * 上のノードより大きければ入れ換えていく
   */ 

  if(parent(pos) == -1) {
    //親がいない
    return;
  }
 
  if( heap[pos] > heap[parent(pos)] ) {
    swap(&heap[pos], &heap[parent(pos)]);
    changeUp(heap, parent(pos));
  }

}


void insert(int* heap, int heapSize, int insertKey) {
  
  heap[heapSize] = insertKey;

  changeUp(heap, heapSize);

}

void extractMax(int *heap, int heapSize) {
  
  printf("%d\n", heap[1]);

  heap[1] = heap[heapSize];

  maxHeapify(heap, 1, heapSize-1);

}



int main() {

  int* heap;
  int heapSize;
  int insertKey;
  char* input[10];

  int i;

  heapSize = 0;
  heap = (int*)malloc( sizeof(int) * (ARRAY_SIZE) );

  while(1) {
    scanf("%s", input);
  
    if( strcmp( input, "insert" ) == 0 ) {
      scanf("%d", &insertKey);
      heapSize += 1;
      insert(heap, heapSize, insertKey);
    }
    else if( strcmp( input, "extract" ) == 0 ) {
      extractMax(heap, heapSize);
      heapSize -= 1;
    }
    else if( strcmp( input, "end" ) == 0 ) {
      break;
    }
    
  }
  



  return 0;

}