#include <stdio.h>
#include <string.h>
int H=0,A[2000001];
void maxHeapify(int);
void insert(int);
int extract();
int main(){
  char command[10];
  int k;
  while(1){
    scanf("%s",command);
    if(!strcmp(command,"insert")){
      scanf("%d",&k);
      insert(k);
    }
    else if(!strcmp(command,"extract")){
      k=extract();
      printf("%d\n",k);
    }
    else break;
  }

  return 0;
}
void insert(int k){
  int i;
  H++;
  A[H]=k;
  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }
}
int extract(){
  int i,k;
  k=A[1];
  A[1]=A[H];
  H--;
  maxHeapify(1);
  return k; 
}
void maxHeapify(int i){
  int l=i*2,r=i*2+1,large,tmp;
  if(l<=H && A[l]>A[i])large=l;
  else large=i;
  if(r<=H && A[r]>A[large])large=r;
  if(large!=i){
    tmp=A[large];
    A[large]=A[i];
    A[i]=tmp;
    maxHeapify(large);
  }
}

