#include <stdio.h>
#include <string.h>

int T[2000000];
int size;


int parent(int i)
{
  return i/2;
}
int left(int i)
{
  return 2*i;
}
int right(int i)
{
  return 2*i+1;
}

void maxHeapify(int i)
{
  int l,r,tmp,max=0;
  l=left(i);
  r=right(i);
  if(l<=size&&T[l]>T[i])
    {
      max=l;
    }
  else
    {
      max=i;
    }
  if(r<=size&&T[r]>T[max])
    {
      max=r;
    }
  if(max!=i)
    {
      tmp=T[i];
      T[i]=T[max];
      T[max]=tmp;
      maxHeapify(max);
    }
}

void heapIncreaseKey(int i,int key)
{
  int tmp;
  if(key<T[i])
    {
      return;
    }
  T[i]=key;
  while(i>1&&T[parent(i)]<T[i])
    {
      tmp=T[i];
      T[i]=T[parent(i)];
      i=parent(i);
    }
}

void maxHeapInsert(int key)
{
  size=size+1;
  T[size]=-2000000000;
  heapIncreaseKey(size,key);
}


int heapExtractMax(void)
{
  int max=0;
  if(size<1)
    {
      return 0;
    }
  max=T[1];
  T[1]=T[size];
  size=size-1;
  maxHeapify(1);
  return max;
}





main()
{
  char command[10];
  int key;
  while(1)
    {
      scanf("%s",command);
      if(strcmp(command,"end")==0)
	{
	  break;
	}
      if(strcmp(command,"insert")==0)
	{
	  scanf("%d",&key);
	  maxHeapInsert(key);
	}
      if(strcmp(command,"extract")==0)
	{
	  printf("%d\n",heapExtractMax());
	}
    }
  return 0;
}