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

int n, e;
int *N;

void maxHeapify(int i){
  int l, r, largest, a;

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

  if(l <= n && N[l] > N[i]) largest = l;

  else largest = i;

  if(r <= n && N[r] > N[largest]) largest = r;

  if(largest != i){
    a = N[i];
    N[i] = N[largest];
    N[largest] = a;
    maxHeapify(largest);
  }
}

void buildMaxHeap(){
  int i;

  for(i = n / 2; i >= e; i--) maxHeapify(i);
}

int main(){
  int i;
  char *x;

  N = (int *)malloc(sizeof(int) * 2000000);
  n = 0;
  e = 0;

  while(1){
    scanf("%s", x);
    if(strcmp(x, "insert") == 0){
      n++;

      scanf("%d", &N[n]);

      buildMaxHeap();
    }

    else if(strcmp(x, "extract") == 0){
      printf("%d\n", N[e]);

      e++;

      buildMaxHeap();
    }

    else if(strcmp(x, "end") == 0) break;
  }

  free(N);

  return 0;
}