#include<stdio.h>
#include<stdlib.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, j;
  int *A;
  char *x;

  A = (int *)malloc(sizeof(int) * 2000000);
  N = (int *)malloc(sizeof(int) * 2000000);
  x = (char *)malloc(sizeof(char) * 8);

  n = 0;
  e = 0;
  i = 0;

  while(1){
    scanf("%s", x);
    if(x[0] == 'i'){
      n++;

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

      buildMaxHeap();
    }

    else if(x[0] == 'e' && x[1] == 'x'){
      A[i] = N[e];

      i++;
      e++;

      buildMaxHeap();
    }

    else if(x[0] == 'e' && x[1] == 'n') break;
  }

  for(j = 0; j < i; j++) printf("%d\n", A[j]);

  free(A);
  free(N);
  free(x);

  return 0;
}