#include<stdio.h>
 
#define INF 1000000
#define K 2000000
 
int n = 0;
int s[K];
 
void increase(int *s, int i, int key){
  int tmp;
 
  s[i] = key;
 
  while(i > 1 && s[i/2] < s[i]){
    tmp = s[i];
    s[i] = s[i/2];
    s[i/2] = tmp;
    i = i/2;
  }
}
 
void insert(int *s, int k){
  n += 1;
  s[n] = -INF;
  increase(s, n, k);
}
 
void maxHeapify(int *s, int i){
  int l, r, tmp, largest;
 
  l = 2*i;
  r = 2*i + 1;
 
  if(l <= n && s[l] > s[i]) largest = l;
  else largest = i;
 
  if(r <= n && s[r] > s[largest]) largest = r;
 
  if(largest != i){
    tmp = s[i];
    s[i] = s[largest];
    s[largest] = tmp;
    maxHeapify(s, largest);
  }
}
 
int extractMax(int *s){
  int max;
 
  max = s[1];
  s[1] = s[n];
  n--;
  maxHeapify(s, 1);
 
  return max;
}
 
int main(){
  int i=0, k, j, max[K];
  char chil[10];
 
  while(1){
    scanf("%s", chil);
 
    if(chil[0] == 'i'){
      scanf("%d", &k);
      insert(s, k);
    }
 
    else if(chil[1] == 'x'){
      max[i] = extractMax(s);
      i++;
    }
    else if(chil[1] == 'n') break;
  }
 
  for(j = 0; j < i; j++) printf("%d\n", max[j]);
 
  return 0;
}