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

int heaps[2000000], h = 0;

void heapify(int a[], int i) {
  int largest, b;
  int l = i * 2;
  int r = i * 2 + 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) {
    b = a[i];
    a[i] = a[largest];
    a[largest] = b;
    heapify(a, largest);
  }
}

void maxheap(int a[], int i, int parent) {
  int b;
  while (i > 1 && a[i] > a[i / 2]) {
    b = a[i];
    a[i] = a[i / 2];
    a[i / 2] = b;
    i = i / 2;
  }
}

void insert(int a[], int key, int i) {
  int parent;
  a[i] = key;
  parent = i / 2;

  maxheap(a, i, parent);
}

int extract(int a[], int i) {
  int parent;
  int max = a[1];
  a[1] = a[i];
 
  return max;
}

int main(void) {
  int key;
  char order[10];

  while (1) {
    scanf("%s", order);
    if (strcmp(order, "insert") == 0) {
      scanf("%d", &key);
      h++;
      insert(heaps, key, h);
    }
    else if (strcmp(order, "extract") == 0) {
      printf("%d\n", extract(heaps, h));
      h--;
      heapify(heaps, 1);
    }
    else
      break;
  }

  return 0;
}

