#include <stdio.h>
#define ORDERMAX 2000000
#define MAX 2000000001
#define NIL -1073741824

void insert(int);
int extractMax(void);
void scan(void);
void swapping(int *,int *);
void perfecttree(int);

int A[MAX],H;

int main(){
  scan();
  
  return 0;
}

void scan(void){
  char order[8];
  int key;
  while(1){
    scanf("%s",order);
    if(order[2] == 's'){
      scanf("%d",&key);
      insert(key);
    }
    else if(order[2] == 'd') break;
    else printf("%d\n",extractMax());
  }
}

void insert(int key){
  int i;
  H++;
  A[H] = NIL;
  i = H;

  if(key < A[i]) return;
  A[i] = key;
  while(i > 1 && A[i / 2] < A[i]){
    swapping(&A[i],&A[i / 2]);
    i = i / 2;
  }
}

void swapping(int *a,int *b){
  int temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

int extractMax(void){
  int ret;
  if(H < 1) return NIL;
  ret = A[1];
  A[1] = A[H];
  H--;
  perfecttree(1);
  return ret;
}

void perfecttree(int i){
  int big,left,right,j;
 
  left = 2 * i;
  right = 2 * i + 1;
  
  if(left < H + 1 && A[left] > A[i]) big = left;
  else big = i;
  if(right < H + 1 && A[right] > A[big]) big = right;
  
  if(big != i){
    swapping(&A[i],&A[big]);
    perfecttree(big);
  }
}

