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

#define N 10000000

void maxHeapify(int*, int);
void buildMaxHeap(int*);
int heapExtractMax();
void maxHeapInsert(int);
void heapIncreaseKey(int, int);

unsigned int *A;
int num = 0;

int main(){
  char str[10];
  int i = 0;

  A = malloc(sizeof(int)*N+1);
  
  while(1){
    scanf("%s", str);
    if(strcmp(str, "insert") == 0){
      scanf("%d", &i);
      maxHeapInsert(i);
      //printf("insert %d done\n", i);
    }
    if(strcmp(str, "extract") == 0){
      printf("%d\n", heapExtractMax());
      // printf("done\n");
    }
    if(strcmp(str, "end") == 0){
      break;
    }
    /*
    for(i = 1; i <= num; i++){
      printf(" %d", A[i]);
    }
    printf("\n");
    */
  }
  return 0;
}

void maxHeapify(int* A, int i){
  int l, r, largest, temp;

  l = 2*i;
  r = 2*i+1;

  if (l <= num && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }

  if(r <= num && A[r] > A[largest]){
    largest = r;
  }

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(A, largest);
  }
}

void buildMaxHeap(int *A){
  int i;
  
  for(i = num/2; i > 0; i--){
    maxHeapify(A, i);
  }
}

int heapExtractMax(){
  int max;
  
  if(num < 1){
    return -1;
  }
    max = A[1];
    A[1] = A[num];
    num--;
    maxHeapify(A,1);
    return max;
}

void maxHeapInsert(int key){
  int i;

  num++;
  A[num] = -2100000000;
  /*  
  printf("maxheapInsert\n");
  for(i = 1; i <= num; i++){
    printf(" %d", A[i]);
  }
  printf("\n");
  */
  
  heapIncreaseKey(num, key);
}

void heapIncreaseKey(int i, int key){
  int temp;
  
    A[i] = key;
    // printf("input %d\n", A[i]);
    while(i > 1 && A[i/2] < A[i]){
      temp = A[i];
      A[i] = A[i/2];
      A[i/2] = temp;
      
      i = i/2;
    }
    /*
      printf("maxIncreaseKey\n");
      for(i = 1; i <= num; i++){
      printf(" %d", A[i]);
      }
      printf("\n");
*/
}

