#include<stdio.h>
#include<string.h>
#define MAX 2000001

void insert(int *, int);
void extractMax(int *);
void maxHeapify(int [], int);
void buildMaxHeap(int []);
int left(int);
int right(int);
void swap(int *, int, int);

int H=1;

main()
{
  int S[MAX], k, i;
  char com[20];

  while(strcmp(com, "end") != 0)
    {
      scanf("%s", com);

      if(com[0] == 'i')
	{
	  scanf("%d", &k);
	  insert(S, k);
	}
      else if(strcmp(com, "extract") == 0)
	{
	  extractMax(S);
	}
    }

  return 0;
}

void insert(int *S, int k)
{
  S[H] = k;
  buildMaxHeap(S);
  H++;
}

void extractMax(int *S)
{
  if(H < 2)
    {
      printf("Error\n");
      return;
    }

  printf("%d\n", S[1]);
  S[1] = S[H];
  H--;

  maxHeapify(S, 1);
}

void maxHeapify(int A[], int i)
{
  int l, r, largest;
  
  l = left(i);
  r = right(i);
  
  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i)
    {
      swap(A, i, largest);
      maxHeapify(A, largest);
    }
}

int left(int i)
{
  return 2*i;
}

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

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

void buildMaxHeap(int A[])
{
  int i;
  
  for(i=H/2; i>0; i--) maxHeapify(A, i);
}