#include<stdio.h>

#define N 2000000

void insert(int);
void maxHeapify(int);
void buildMaxHeap();
int extractMax();

int H[N];
int heapSize;


int main()
{
  int n, i, key;
  char str[8];
  
  heapSize=0;
  for(i=0; i<N; i++)
    {
      scanf("%s", str);
      if(str[0]=='i')
	{
	  scanf("%d", &key);
	  insert(key);
	}
      else if(str[1]=='x')
	{
	  buildMaxHeap();
	  printf("%d\n", extractMax());
	}
      else
	break;
    }
  return 0;
}
void insert(int key)
{
  H[heapSize] = key;
  heapSize++;
}
void maxHeapify(int i)
{
  int maxi=i;
  int tmp;

  if((i+1)*2 <= heapSize)
    {
      if(H[(i+1)*2 -1] >= H[i])
	maxi = (i+1)*2 -1;
    }
  if((i+1)*2 +1 <= heapSize)
    if(H[(i+1)*2] >= H[i])
      if(H[(i+1)*2] >= H[maxi])
	maxi = (i+1)*2;

  if(maxi != i)
    {
      tmp = H[i];
      H[i] = H[maxi];
      H[maxi] = tmp;
      
      maxHeapify(maxi);
    }
}
void buildMaxHeap()
{
  int i;
  for(i=heapSize/2 -1; i>=0; i--)
    maxHeapify(i);
}
int extractMax()
{
  int max = H[0];

  H[0]=H[heapSize-1];
  heapSize--;
  
  return max;
}