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

#define N (2000000)
int array[N];
int num;

void swap(int* a, int *b) {
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void swap_array(int n) {
  if (n == 0) return;
  int parent = (n - 1) / 2;
  if (array[n] > array[parent]) {
    swap(&array[n], &array[parent]);
    swap_array(parent);
  }
}

void shift_down(int i) {
  int child = 2 * i + 1;
  if (child >= num) return; 
  if (array[child] < array[child + 1]) {
    child++;
  }
  if (array[i] < array[child]) {
    swap(&array[i], &array[child]);
    shift_down(child);
  }
}

void push(int n) {
  array[num] = n;
  num++;
  swap_array(num - 1);
}

int pop() {
  int t = array[0];
  array[0] = array[--num];
  shift_down(0);
  return t;
}

int main() {
  char s[80];
  while (scanf("%s", &s)) {
    if (strcmp(s, "end") == 0) break;
    if (s[0] == 'e') {
      printf("%d\n", pop());
    } else {
      int d;
      scanf("%d", &d);
      push(d);
    }
  }

  return 0;
}