#include <stdio.h>
#define N 2000001

void MaxHeapify(int *, int);
void Insert(int *, int);
void Extract(int *);

int h = 0;

int main(){
  int a[N], key[N];
  int i = 0, j;
  char order[N][8];

  while( 1 ){
      scanf("%s", order[i]);
      if(order[i][2] == 'd') break;
      else if(order[i][0] == 'i') scanf("%d", &key[i]);
      i++;
  }

  i = 0;
  while( 1 ){    
    if(order[i][2] == 'd') break;
    else if(order[i][0] == 'i') Insert(a, key[i]);
    else Extract(a);
    i++;
    //for(j = 1;j < h+1;j++)printf("%d: %d ",j, a[j]);
    //printf("\n"); 
  }

  return 0;
}

void MaxHeapify(int *a, int i){
  int left, right, large, change;

  if(i * 2 <= h) left = i * 2;
  else left = i;
  if(i * 2 + 1 <= h) right = i * 2 + 1;
  else right = i;


  if(left < h + 1 && a[left] > a[i]) large = left;
  else large = i;
  if(right < h + 1 && a[right] > a[large]) large = right;
  
  if(large != i){
    change = a[i];
    a[i] = a[large];
    a[large] = change;
    MaxHeapify(a, large);
  }
}

void Insert(int *a, int key){
  int i, change;

  h++;
  i = h;
  a[i] = key;
  while(i > 1 && a[i / 2] < a[i]){
    change = a[i];
    a[i] = a[i / 2];
    a[i / 2] = change;
    i /= 2;
  }
}

void Extract(int *a){
  int max;

  max = a[1];
  a[1] = a[h];
  h--;
  MaxHeapify(a, 1);

  printf("%d\n", max);
}