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

void in(int *, int);
void ext(int *);
void maximum(int *, int);

int n = 0;

main(){
  int i;
  int t[2000002];
  char a[10];
  
  while(1){
    scanf("%s", a);
    if(a[2] == 'd') break;
    else if(a[0] == 'i'){
      scanf("%d", &t[0]);
      in(t, t[0]);
    }
    else ext(t);
  }
  
  return 0; 
}
void maximum(int *t, int i){
  int l, r, large, c;
  
  if( i*2+1 < n + 1) r = i*2+1;
  else r = i;
  if( i*2 < n + 1) l = i*2;
  else l = i;
  
  if(l <= n && t[l] > t[i]) large = l;
  else large = i;
  
  if(r <= n && t[r] > t[large])large = r;
  
  if(large != i){
    c = t[i];
    t[i] = t[large];
    t[large] = c;
    maximum(t, large);
  }
}
void in(int *t, int a){
  int i,c;
  
  n++;
  i = n;
  t[n] = a;
  
  while(i > 1 && t[i/2] < t[i]){
    c = t[i];
    t[i] = t[i/2];
    t[i/2] = c;
    i /= 2;
  }
}
void ext(int *t){
  
  printf("%d\n", t[1]);
  
  if(n > 1)t[1] = t[n];
  
  n--;
  
  if(n > 1) maximum(t, 1);
}


