#include<stdio.h>
#define INF -222222222

void insert(int);
void build();
void Max_h();
int Ex_Max();

int K_c = 0;//配列Kの個数
int E_c = 0;//配列Eの個数
int K[1000000], E[1000000];

int main(){
  int i;
  int k;
  char order[10];

  while(1){
    scanf("%s", order);
    if(order[0] == 'e' && order[1] == 'n'){
      break;
    }else if(order[0] == 'i'){
      scanf("%d", &k);
      insert(k);
    }else if(order[0] == 'e' && order[1] == 'x'){
      E[E_c] = Ex_Max();
      Max_h(1);      
      E_c++;
    }
  }

  for(i = 0; i < E_c; i++){
    printf("%d\n", E[i]);
  }

  return 0;
}

void insert(int k){
  int temp, i;
  
  K_c++;  
  K[K_c] = k;

  i = K_c;

  while(i > 1 && K[i / 2] < K[i]){
    temp = K[i];
    K[i] = K[i / 2];
    K[i / 2] = temp;

    i = i / 2;
  }
}

int Ex_Max(){
  int max;

  max = K[1];
  K[1] = K[K_c];

  K_c--;

  return max;
}

//以下、前問から引用

void Max_h(int i){
  int left, right, largest = 0;
  int temp;

  left = i*2;
  right = i*2 + 1;

  if(left <= K_c && K[left] > K[i]) largest = left;
  else largest = i;

  if(right <= K_c && K[right] > K[largest]) largest = right;

  if(largest != i){
    temp = K[i];
    K[i] = K[largest];
    K[largest] = temp;

    Max_h(largest);
  }
}

