#include <stdio.h>

void maxh(int* ,int);
int i,num,a[2000000];
int main()
{int n,e,h=0;
  char s[10];
  
  while(1){
    scanf("%s",s);
    if(s[2]=='d')break;
    else if(s[0]=='i'){
      h++;   
      i=h;
      scanf("%d",&n);
      a[i] = n;
      while (i > 1 && a[i/2] < a[i]){
	e= a[i]; 
	a[i]= a[i/2];
	a[i/2]=e;
	i = i/2;
      }
    }
    else {
      printf("%d\n",a[1]);

      a[1]=a[h];
      h--;

      maxh(a,1);
   
    }

  }


  return 0;
}
void maxh(int a[], int i){
  int l,r,e,largest;        


  l = 2*i;
  r = 2*i+1;
  if (l <= num && a[l] > a[i])
    largest = l;
  else 
    largest = i;
  if (r <= num && a[r] > a[largest])
    largest = r;
  if (largest != i){
    e=a[i]; 
    a[i]=a[largest];         
    a[largest]=e;    
    maxh(a, largest);
  }

} 