#include <stdio.h>
#include <string.h>
#define nil -1
#define max 2000001
typedef struct{
  int key;
  int parent;
  int right;
  int left;
} node;
int parent(int);
int left(int);
int right(int);
void maxHeapify(int);
node heapExtractMax(void);
void maxHeapInsert(int);
void heapIncreaseKey(int, int);
int H = 0;
node data[max];

int main()
{
  int key;
  char order[8];
  node output;
 
  while(1){
    scanf("%s",order);
    if(strcmp(order,"end") == 0) break;
    if(strcmp(order,"insert") == 0){
      scanf("%d",&key);
      maxHeapInsert(key); }
    if(strcmp(order,"extract") == 0){
      output = heapExtractMax();
      if(output.key != nil) printf("%d\n",output.key); }
  }
  
  return 0;
}

int parent(int i)
{
  return i/2;
}

int left(int i)
{
  return 2*i;
}

int right(int i)
{
  return 2*i + 1;
}

void maxHeapify(int i)
{
  int l, r, largest, ForKeep;

  l = left(i);
  r = right(i);

  if(l <= H && data[l].key > data[i].key) largest = l;
  else largest = i;

  if(r <= H && data[r].key > data[largest].key) largest = r;
  
  if(largest != i){
    ForKeep = data[i].key;
    data[i].key = data[largest].key;
    data[largest].key = ForKeep;
    maxHeapify(largest); }
}

node heapExtractMax(void)
{
  node Max, NIL;
  NIL.key = nil;
  if(H < 1) return NIL; 
  
  Max = data[1];
  data[1] = data[H];
  H--;
  maxHeapify(1); 

  return Max;
}

void maxHeapInsert(int key)
{
  H++;
  data[H].key = -200000;
  heapIncreaseKey(H, key);
}

void heapIncreaseKey(int i, int key)
{
  int ForChange;

  if(key < data[i].key) return;
    
  data[i].key = key;

  while(i > 1 && data[parent(i)].key < data[i].key){
    ForChange = data[i].key; 
    data[i].key = data[parent(i)].key;
    data[parent(i)].key = ForChange;
    i = parent(i); }
  
}

