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

int A[2000000];

int largest = 0;

int left(i){
  return 2*i;
}

int right(i){
  return (2*i)+1;
}

void maxHeapify(int i, int H){
  int b;
  int l = left(i);
  int r = right(i);
  if(l <= H && A[l] > A[i])
    largest = l;
  else{
    largest = i;
  }
  if(r<=H && A[r] > A[largest]){
    largest = r;
  }

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


int main(){

  int i, cnt= 1, Max;
  char C[8];

  while(scanf("%s", C)==1){
    if(C[0] == 'i'){
      scanf("%d", &A[cnt]);
      i=cnt;
      while(i > 1 && A[i/2] < A[i]){
        Max = A[i/2];
        A[i/2] = A[i];
        A[i] = Max;
        i = i/2;
      }
      cnt++;
    }
    else if(strncmp(C, "ex", 2) == 0){
      printf("%d\n",A[1]);
      A[1] = A[--cnt];
      maxHeapify(1, cnt);
    }
    else break;
  }
  return 0;
}
