#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define TRUE 1
#define FALSE -1
int size,A[MAX+1];

void swap( int  *a , int  *b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

void buildmaxHeapify(int k)
{
  int left,right,big;
  left=2*k;
  right=2*k+1;

  if(left<=size && A[left]>A[k])big=left;
  else big=k;
  if(right<=size && A[right] > A[big])big=right;

  if(big!=k)
    {
      swap(&A[k],&A[big]);
      buildmaxHeapify(big);
    }
}

int extract()
{
  int max;
  if(size<1)return FALSE;
  max=A[1];
  A[1]=A[size--];
  buildmaxHeapify(1);
  return max;
}

void increase(int k,int key)
{
  if(key<A[k])return;
  A[k]=key;
  while(k>1 && A[k/2]<A[k])
    {
      swap(&A[k],&A[k/2]);
      k=k/2;
    }
}

void insert(int key)
{
  size++;
  A[size]= FALSE;
  increase(size,key);
}

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