#include <stdio.h>
#define k_max 2000001
int size=0;
int que[k_max];
#define swap(a,b){int temp=que[a]; que[a]=que[b]; que[b]=temp;}

int max_index(int ,int );
void insert(int);
int extract();

int main(){
  char ope[10];
  int i,j,k;
  
  while(1){
    scanf("%s",ope);
    if(ope[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    if(ope[0]=='e'){
      if(ope[1]=='x')
	printf("%d\n",extract());
      if(ope[1]=='n') break;
    }
  }
  return 0;
}


int max_index(int a,int b){
  if(que[a]>que[b]) return a;
  else return b;
}

void insert(int k){
  int i;
  
  size++;
  que[size]=k;
  i=size;
  
  while(que[i]>que[i/2] && i>1){
    swap(i,i/2);
    i=i/2;
  }
}

int extract(){
  int key=que[1];
  int i, node_max;
  
  que[1]=que[size];
  size--;
  i=1;
  
  while(i*2 <= size ){
    if(i*2+1 <= size)
      node_max=max_index(i*2,i*2+1);
    else node_max=i*2;
    if(max_index(node_max,i)==node_max){swap(node_max,i);i=node_max;}
    else break;    
  }
  return key;
}



