#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define NIL -1
int A[MAX+1],H;
int left(int i){ return 2*i;}
int right(int i){ return 2*i+1;}
int parent(int i){ return i/2;}

/*void print(int u){
  printf("node %d: key = %d, ",u,A[u]);
  if(u>1) printf("parent key = %d, ",A[parent(u)]);
  if(left(u)<=n) printf("left key = %d, ",A[left(u)]);
  if(right(u)<=n) printf("right key = %d, ",A[right(u)]);
  printf("\n");
}*/

void maxHeapify(int i){
  int l,r,largest,tmp;
  l=left(i);
  r=right(i);

  if(A[i]<A[l]&&l<=H) largest=l;
  else largest=i;
  if(A[largest]<A[r]&&r<=H) largest=r;

  if(largest!=i){
    tmp=A[i]; A[i]=A[largest]; A[largest]=tmp;
    maxHeapify(largest);
  }
}
/*void buildMaxHeap(void){
  int i;
  for(i=n/2;i>0;i--) maxHeapify(i);
  }*/
void heapincreaseKey(int i,int key){
  int tmp;
  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);
  }
}
void insert(int key){
  H++;
  A[H]=NIL;
  heapincreaseKey(H,key);
}

int extract(void){
  int max=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return max;
}
int main(){
  int i,key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }else if(strcmp(com,"extract")==0){
      printf("%d\n",extract());
    }else break;
  }
  return 0;
}


