#include <stdio.h>
#include <stdlib.h>
#define INF 1000000000
#define MAX 2000000

int size = 0;
int A[MAX];

void maxHeapinsert(int);
void heapIncreaseKey(int,int);
int heapExtractMax(void);
int left(int);
int right(int);
void maxHeapify(int);

int main() {

  int key,max;
  char str[10];
  
  while(1) {
    
    scanf("%s",str);

    if(str[0] == 'i') {
      scanf("%d",&key);
      maxHeapinsert(key);
    }
    
    if(str[2] == 'd')
      break;
    
    if(str[0] == 'e') {
      max = heapExtractMax();
      printf("%d\n",max);
    }
  }

  return 0;
}



void maxHeapinsert(int key)
{
  size++;
  A[size] = -INF;
  heapIncreaseKey(size,key);
}


void heapIncreaseKey(int i,int key)
{
  int temp;
  if(key < A[i]) {
    exit(0);
  }

  A[i] = key;
  while(i > 1 && A[i/2] < A[i]) {

    temp = A[i];
    A[i] = A[i/2];
    A[i/2] = temp;
    i = i/2;
  }

}



int heapExtractMax(void)
{
  int max;
  if(size < 1) {
    exit(1);
  }
  
  max = A[1];
  A[1] = A[size];
  size--;
  maxHeapify(1);

  return max;
}

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

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

void maxHeapify(int i)
{
  int l,r,largest,temp;
  l = left(i);
  r = right(i);

  if(l <= size && A[l] > A[i])
    largest = l;
  else
    largest = i;
  
  if(r <= size && A[r] > A[largest])
    largest = r;

  if(largest != i) {
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
  
}

