#include <stdio.h>

int A[1000001],size;

void maxHeapify(int i){
  int l = i*2;
  int r = i*2+1;
  int lar,tmp;
  
  if(l<=size && A[l]>A[i])lar=l;
  else lar=i;
  if(r<=size && A[r]>A[lar])lar=r;

  if(i!=lar){
    tmp = A[i];
    A[i] = A[lar];
    A[lar] = tmp;
  maxHeapify(lar);
  }
}

int main(){

  int i,tmp;
  char com[10];
  size=0;
  
  
  while(1){
    scanf("%s",com);
    if(com[0]=='i'){
      size++;
      scanf("%d",&A[size]);
      i=size;
      while(i>1 && A[i/2]<A[i]){
	tmp = A[i];
	A[i] = A[i/2];
	A[i/2] = tmp;
	i = i/2;
      }
      
    }else if(com[0]=='e' && com[1]=='x'){
      printf("%d\n",A[1]);
      A[1]=A[size];
      size--;
      maxHeapify(1);
    }else if(com[0]=='e' && com[1]=='n')break;
    //  for(i=1;i<=size;i++)printf(" %d",A[i]);
    // printf("\n");
  }
  
  return 0;
}

