#include<stdio.h>

#define MAX 2000001

int heap=0;

void maxHeapify(int *, int);
void buildMaxHeap(int *);
int heapExtractMax(int *);
void maxHeapInsert(int *,int);
void heapIncreaseKey(int *,int,int);

int main(){
  int key,value;
  int A[MAX];
  char str[10];

  while(1){
    scanf("%s",str);

    if(str[0]=='i'){
      scanf("%d",&key);
      maxHeapInsert(A,key);
    }

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

    else break;
  }
      
  return 0;
}

void maxHeapify(int *A, int i){
  int left,right,largest,tmp;

  left=2*i;
  right=left+1;

  if(left<=heap && A[left]>A[i]) largest=left;
  else largest=i;
  if(right<=heap && A[right]>A[largest]) largest=right;

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

void buildMaxHeap(int *A){
  int i;

  for(i=heap/2;1<=i;i--) maxHeapify(A,i);
}

int heapExtractMax(int *A){
  int max;

  max=A[1];
  A[1]=A[heap];
  heap--;
  maxHeapify(A,1);
  
  return max;
  
}

void maxHeapInsert(int *A,int key){
  heap++;
  A[heap]=-1*MAX;
  heapIncreaseKey(A,heap,key);
}

void heapIncreaseKey(int *A,int i,int key){
  int tmp;
  A[i]=key;
  while(i>1 && A[i/2]<A[i]){
    tmp=A[i];
    A[i]=A[i/2];
    A[i/2]=tmp;
    i=i/2;
  }
}

