#include<stdio.h>
#include<string.h>
#define INF 2000000;

void maxHeapInsert(int );
void heapIncreaseKey(int);
int  extractMax( );
void maxHeapify(int  );

int heap[2000010];
int heapsize = 1;

int main(){

  char command[10];
  int flag = 1;
  int key;
  int sumnode = 0;
  int i;
  int max;
  while(flag){

    scanf("%s",command);


    if((strcmp(command,"insert")) == 0){

      scanf("%d",&key);
      maxHeapInsert(key);
      sumnode = sumnode + 1;

    }

    else if((strcmp(command,"extract")) == 0){

      max =extractMax();
      sumnode = sumnode -1;
      printf("%d\n",max);


    }

    else if((strcmp(command,"end")) == 0) {

      flag = 0;

    }

  }

  return 0;

}

void maxHeapInsert(int key){

  int swap;

  //printf("test\n");
  heapsize = heapsize + 1;

  heap[heapsize] = -INF;

  heapIncreaseKey(key);

}

void heapIncreaseKey( int key){

  int swap;
  //printf("test2\n");

  if (key < heap[heapsize]){

    printf("output error new key is smaller than current key\n");

  }


  heap[heapsize] = key;

  while(heapsize >1 && heap[heapsize / 2] < heap[heapsize]){

    swap = heap[heapsize];

    heap[heapsize] = heap[heapsize/2];

    heap[heapsize/2] = swap;

  }

}

int extractMax(){

  int MAX;

  // printf("test3\n");
  if(heapsize < 1){

    printf("heap under flow\n");

  }

  MAX = heap[1];

  heap[1] = heap[heapsize];

  heapsize = heapsize - 1;

  maxHeapify(1);

  return MAX;

}

void maxHeapify(int i){

  int left;
  int right;
  int largest;
  int swap;
  left = i * 2;
  right = i * 2 + 1;


  if(left <= heapsize && heap[left] > heap[i]){

    largest = left;

  }

  else{

    largest = i;

  }

  if(right <= heapsize && heap[right] > heap[largest]){

    largest = right;

  }


  if(largest != i){

    swap = heap[i];

    heap[i] = heap[largest];

    heap[largest] = swap;

    maxHeapify(largest);

  }

}