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

#define N 2000005



typedef struct{
  int key, lk, rk, pk;
}Node;



void Insert(int);
int Extractmax();
void MaxHeapify(int);
void buildMaxHeap();

Node node[N];
int hsize;
	    
int main () {
  int i, n = 0;
  char str[8];


  while(1) {
    scanf("%s",str);
    if(strcmp(str,"end") == 0) break;

    else if(strcmp(str,"insert") == 0) {
      scanf("%d",&n);
      Insert(n);
    }

    else printf("%d\n",Extract());
  }


  return 0;
}


void Insert(int n) {
  int i;
  int tmp;

  hsize++;

  node[hsize].key =  n;

  if(hsize > 1) node[hsize].pk = hsize/2;
  
  if(hsize >= 3) {
    node[hsize/2].lk = node[hsize/2*2].key;
    node[hsize/2].rk = node[hsize/2*2+1].key;
  }

  i = hsize;

  while( i > 1 && node[node[i].pk].key < node[i].key) {
    tmp = node[node[i].pk].key;
    node[node[i].pk].key = node[i].key;
    node[i].key = tmp;
    i = node[i].pk;
  }

 

}


int Extract() {
  int max;
  
  if(hsize < 1) return 0;

  //buildMaxHeap();

  max = node[1].key;
  node[1] = node[hsize];
  hsize--;
  MaxHeapify(1);

  return max;
}


void MaxHeapify(int x) {
  int left = 2 * x, right = 2 * x + 1, large = 0, tmp = 0;


  if(left <= hsize && node[left].key > node[x].key) large = left;
  
  else large = x;
  
  if(right <= hsize && node[right].key > node[large].key) large = right;

  if(large != x) {
    tmp = node[x].key;
    node[x].key = node[large].key;
    node[large].key = tmp;
    MaxHeapify(large);
  }
 
}


void buildMaxHeap() {
  int i;
  
  for(i = hsize/2 ; i >= 1 ; i--) MaxHeapify(i);
}

