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

int H;

void maxHeapify(int *A, int i);

int main(int argc, char *argv[])
{
  int i, x;
  int A[2000000 + 1];
  char cmd[7 + 1];

  H = 0;

  scanf("%s", cmd);
  while (strcmp(cmd, "end")) {
    if (!strcmp(cmd, "insert")) {
      scanf("%d", &x);
      A[H+1] = x;
      H++;
      for (i = H / 2; i > 0; i--) maxHeapify(A, i);
    } else if (!strcmp(cmd, "extract")) {
      x = A[1];
      for (i = 2; i <= H; i++) A[i-1] = A[i];
      H--;
      for (i = H / 2; i > 0; i--) maxHeapify(A, i);
      printf("%d\n", x);
    }
    scanf("%s", cmd);
  }

  return 0;
}

void maxHeapify(int *A, int i)
{
  int l, r;
  int largest;
  int tmp;
  
  l = 2 * i;
  r = 2 * i + 1;
  
  if (l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if (r <= H && A[r] > A[largest]) largest = r;
  
  if (largest != i) {
    tmp = A[largest];
    A[largest] = A[i];
    A[i] = tmp;
    maxHeapify(A, largest);
  }
}