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

#define MAX 2000000
#define INFTY 1000000

int n, a[MAX+1];

void maxHeapify(int i)
{
  int l, r, largest, tmp;
  l = 2*i;
  r = 2*i+1;

  if(l <= n && a[l] > a[i])
    largest = l;
  else
    largest = i;
  if(r <= n && a[r] >  a[largest])
    largest = r;

  if(largest != i) {
    tmp = a[i];
    a[i] = a[largest];
    a[largest] = tmp;
    maxHeapify(largest);
  }
}

int extract()
{
  int maxv;
  if(n < 1)
    return -INFTY;
  maxv = a[1];
  a[1] = a[n--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key)
{
  int tmp;

  if(key <a[i])
    return ;
  a[i] = key;
  while(i > 1 && a[i/2] < a[i]) {
    tmp = a[i];
    a[i] = a[i/2];
    a[i/2] = tmp;
    i /= 2;
  }
}

void insert(int key)
{
  n++;
  a[n] = -INFTY;
  increaseKey(n, key);
}

int main()
{
  int key;
  char command[10];

  while(1) {
    scanf("%s", command);
    if(strcmp(command, "end") == 0)
      break;
    if(strcmp(command, "insert") == 0) {
      scanf("%d", &key);
      insert(key);
    }
    else {
      printf("%d\n", extract());
    }
  }
  return 0;
}