#include <stdio.h>
#define MAX 2000000

void maxHeapify(int *,int);
void buildMaxHeap(int *);
int heapExtractMax(int *);
void temp(int *,int *);

int j=0;

int main(){
  int i,k,S[MAX];
  char order[8];

  for(i=1;i<MAX;i++){
    scanf("%s",order);
    if(strcmp("insert",order)==0) scanf("%d",&S[++j]);

    else if(strcmp("extract",order)==0){
      buildMaxHeap(S);
      printf("%d\n",heapExtractMax(S));
    }

    else return 0;
  }
}

void maxHeapify(int *A,int i){
  int l,r,largest;

  l=i*2;
  r=i*2+1;

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

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

  if(largest!=i){
    temp(&A[i],&A[largest]);
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;

  for(i=j/2;i>=1;i--) maxHeapify(A,i);
}

int heapExtractMax(int *A){
  int max;

  max=A[1];
  A[1]=A[j];
  j--;
  maxHeapify(A,1);
  return max;
}
  
void temp(int *a,int *b){
  int temp;

  temp=*a;
  *a=*b;
  *b=temp;
}