#include <stdio.h>

#define MAX 2000001

void Ins(int);
void IcK(int,int);
void Ext(void);
void MaxH(int);

int n,A[MAX],size; 

int main()
{
  int i,n;

  char moji[8];

  while(1)
    {

      scanf("%s",moji);
      
      if(moji[0]=='i')
	{
	  scanf("%d",&n);
	  Ins(n);
	}
      if(moji[0]=='e'&&moji[1]=='x')
	{
	  Ext();
	}
      if(moji[0]=='e'&&moji[1]=='n')
	{
	  break;
	}
    }
  return 0;
}


void Ins(int n)
{
  size++;
  A[size]=-MAX;
  IcK(size,n);
}
  
void IcK(int i,int n)
{

  int koukan;
  
  if(n<A[i])printf("error");
  
  A[i]=n;
  
  while(i>1&&A[i/2]<A[i])
    {
      koukan=A[i];
      A[i]=A[i/2];
      A[i/2]=koukan;

      i/=2;
    }
}

void Ext(void)
{
  int max;
  
  if(size<1)printf("error\n");

  printf("%d\n",A[1]);
  A[1]=A[size];
  size--;
  
  MaxH(1);


}
 
void MaxH(int i)
{
  int L,R,lg,koukan;
   
  L=2*i;
  R=2*i+1;
  
  if(L<=size&&A[L]>A[i])lg=L;
  else lg=i;
  
  if(R<=size&&A[R]>A[lg])lg=R;
  
  if(lg!=i)
    {
      koukan=A[i];
      A[i]=A[lg];
      A[lg]=koukan;
      
      MaxH(lg);
    }
}
  

