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

int H;

void insert(int *A, int i);
int extractMax(int *A);
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++;
      insert(A, H);
    } else if (!strcmp(cmd, "extract")) {
      x = extractMax(A);
      printf("%d\n", x);
    }
    scanf("%s", cmd);
  }

  return 0;
}

void insert(int *A, int i)
{
  int p, tmp;

  if (H == 1) return;

  p = (int)floor(i / 2);

  while (p != 0 && A[p] < A[i]) {
    tmp = A[p];
    A[p] = A[i];
    A[i] = tmp;
    i = p;
    p = (int)floor(i / 2);
  }
}

int extractMax(int *A)
{
  int x = A[1], tmp;
  int i, l, r;

  A[1] = A[H--];

  maxHeapify(A, 1);

  return x;
}

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);
  }
}