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

int H;

void insert(int *A, int i);
int extractMax(int *A);

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--];

  i = 1;
  l = 2;
  r = 3;
  while (l <= H) {
    if (A[l] > A[i] && A[l] > A[r]) {
      tmp = A[l];
      A[l] = A[i];
      A[i] = tmp;
      i = l;
      l = 2 * i;
      r = 2 * i + 1;
    } else if (A[r] > A[i] && A[r] > A[l] && r <= H) {
      tmp = A[r];
      A[r] = A[i];
      A[i] = tmp;
      i = r;
      l = 2 * i;
      r = 2 * i + 1;
    } else break;
  }

  return x;
}