#include<stdio.h>
#define MAX 2000001
 
void insert(int *, int);
int extractMax(int *);
void maxHeapify(int [], int);
void buildMaxHeap(int []);
int left(int);
int right(int);
void swap(int *, int, int);
 
int H=1;
 
int main()
{
  int S[MAX], k, i;
  char com[20];
 
  while(1)
    {
      scanf("%s", com);
      
      if(com[0] == 'i')
	{
	  scanf("%d", &k);
	  insert(S, k);
	}
      else if(com[1] == 'x')
	{
	  printf("%d\n", extractMax(S));
	}
      else if(com[2] == 'd')
	{
	  break;
	}
    }
  
  return 0;
}
 
void insert(int *S, int k)
{
  S[H] = k;
  buildMaxHeap(S);
  H++;
}
 
int extractMax(int *S)
{
  int max;

  max = S[1];
  H--;
  S[1] = S[H];
 
  maxHeapify(S, 1);

  return max;
}
 
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);
}