//2020.1.16
//s1270188 xxxmk2
//alds1_09c

#include<stdio.h>
#define N 2000000

//prototype
void maxheap(int);


//global
int data[N+1], num=0;

int main(){
  int i;
  char cmd[10];

  while(1){
    scanf(" %s",cmd);

    if(cmd[0]=='i'){
      scanf("%d",&data[++num]);

      for(i=num/2;i>0;i/=2) maxheap(i);
    }
    
    else if(cmd[0]=='e'){
      if(cmd[1]=='n') break; 
      
      if(cmd[1]=='x'){
	printf("%d\n",data[1]);
	data[1]=data[num--];
	maxheap(1);
      }
    }
  }

  
  return 0;
}

void maxheap(int i){
  int l=i*2, r=i*2+1, max;
  
  if(l<=num && data[l]>data[i]) max=l;
  else max=i;
  if(r<=num && data[r]>data[max]) max=r;

  if(max!=i){
    l=data[i];
    data[i]=data[max];
    data[max]=l;

    maxheap(max);
  }
}

