#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef i32 heap_val;

int cmp_heap_val (const heap_val a, const heap_val b) {
  return a == b ? 0 : a > b ? -1 : 1;
}

typedef struct binaryHeap{
  heap_val *array;
  size_t heap_size;
  size_t max_size;
} heap;

heap* new_binary_heap (void) {
  heap *h = (heap *) calloc (1, sizeof (heap));
  h->array = (heap_val *) malloc (sizeof (heap_val) * (1 + 1));
  h->heap_size = 0;
  h->max_size = 1;
  return h;
}

int32_t get_heap_size (const heap *h) {
  return h->heap_size;
}

int is_empty (const heap *h) {
  return h->heap_size == 0;
}

void free_heap (heap *h) {
  free (h->array);
  free (h);
}

void init_heap (heap *h) {
  h->heap_size = 0;
}

void push (heap *h, const heap_val val) {
  if (h->heap_size == h->max_size) {
    h->max_size = 2 * h->max_size + 1;
    h->array = (heap_val *) realloc (h->array, sizeof (heap_val) * (h->max_size + 1));
  }
  h->heap_size++;
  heap_val *array = h->array;
  size_t k = h->heap_size;
  array[k] = val;
  while(k>1){
    size_t parent = k / 2;
    if (cmp_heap_val (array[parent], array[k]) <= 0) {
      return;
    }
    heap_val swap = array[parent];
    array[parent] = array[k];
    array[k] = swap;
    k = parent;
  }
}

heap_val pop (heap *h) {
  heap_val *array = h->array;
  const heap_val res = array[1];
  array[1] = array[h->heap_size--];
  const size_t n = h->heap_size;
  size_t k = 1;
  while (2 * k  + 1 <= n) {
    int c = cmp_heap_val (array[2 * k], array[2 * k + 1]);
    size_t next = 2 * k + (c <= 0 ? 0 : 1);
    if (cmp_heap_val (array[k], array[next]) <= 0) break;
    heap_val swap = array[k];
    array[k] = array[next];
    array[next] = swap;
    k = next;
  }
  if (2 * k <= n && cmp_heap_val (array[k], array[2 * k]) > 0) {
    heap_val swap = array[2 * k];
    array[2 * k] = array[k];
    array[k] = swap;
  }
  return res;
}

void run (void) {
  heap *h = new_binary_heap ();
  char s[10];
  while (1) {
    scanf ("%s", s);
    if (s[0] == 'i') {
      i32 v;
      scanf ("%" SCNi32, &v);
      push (h, v);
    } else {
      if (s[1] == 'n') break;
      i32 v = pop (h);
      printf ("%" PRIi32 "\n", v);
    }
  }
}

int main (void) {
  run ();
  return 0;
}

