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

#define MAX 2000000
  
int Q[MAX] = {}; 
int heapSize=0;
 
int parent(int);
int left(int);
int right(int);
void maxHeapify(int);
int extractMax(void);
void insert(int);
void increaseKey(int, int);
  
// 
int main(void)
{
  char op[10];
  int val=0;

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

int extractMax(void) {
  if(heapSize < 1){
    printf("heap size is 0!");
    return 0;
  }
  int max = Q[1];
  Q[1] = Q[heapSize];
  heapSize--;
  maxHeapify(1);
  return max;
}
 
void maxHeapify(int i)
{
  int largest=0, temp=0, l=0, r=0;
 
  l = left(i);
  r = right(i);
   
  if((heapSize >= l) && (Q[l] > Q[i])){
    largest = l;
  }
  else{
    largest = i;
  }
    
  if((heapSize >= r) && (Q[r] > Q[largest])){
    largest = r;
  }
 
  if (largest != i){
    temp = Q[i];
    Q[i] = Q[largest];
    Q[largest] = temp;
    maxHeapify(largest);
  } 
 
}

void insert(int key) {
  heapSize++;
  Q[heapSize] = INT_MIN;
  increaseKey(heapSize, key);
}

void increaseKey(int i, int key) {
  Q[i] = key;
  while(i > 1 && Q[parent(i)] < Q[i]){
    int tmp = Q[i];
    Q[i] = Q[parent(i)];
    Q[parent(i)] = tmp;
    i = parent(i);
  }
}

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

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

