#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define N 50000
#define INF 1000000

int h,i,A[N],size;

/*void maxHeapify(int);
void buildMaxHeap(void);
int heapExtractMax(int);
void maxHeapInsert(int,int);
void heapIncreseKey(int);*/

maxHeapInsert(int key){
 size=size+1;
  A[size]=-INF;
  heapIncreseKey(size,key);
}

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


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

int parent(int i){

  return floor(i/2);

}

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

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

maxHeapify(int i){
  int l,r,largest,tmp;

  l=left(i);
  r=right(i);

  if(l<=size && A[l]>A[i]) largest=l;

  else largest=i;

  if (r<=size && A[r]>A[largest]){
 
   largest=r;

  }

  if (largest!=i){

    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;

    maxHeapify(largest);
  }
}

  int main()
  {
    int x;
    char com[20];
    size=0;

    while(com[2]!='d'){

    scanf("%s",com);

    if(com[0]=='i'){
      scanf("%d",&x);
      maxHeapInsert(x);
    }

    else if(com[1]=='x'){printf("%d\n",heapExtractMax());}

    }

    return 0;
  }