#include<stdio.h>

#define NIL -2000000001
#define INFTY 2000000001

int H=1;
int A[INFTY-1];

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

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

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

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

/*void buildMaxHeap(void){
  int i;
  for (i=H/2;i>=1;i--){
    maxHeapify(i);
  }
  }*/

int extract(){
  int maxv;
  if(H<1)return -INFTY;
  maxv=A[1];
  A[1]=A[H--];
   maxHeapify(1);
   return maxv;
}

void increaseKey(int i,int key){
  int temp;
  if(key<A[i])return ;
  A[i]=key;
  while((i>1)&&(A[i/2]<A[i])){
    temp=A[i/2];
    A[i/2]=A[i];
    A[i]=temp;
    i=i/2;
  }
}

void insert(int key){
  H++;
  A[H]=-INFTY;
  increaseKey(H,key);
}

int main(){
  char order[10];
  int key,a;

  while(1){
    scanf("%s",order);
    if(order[2]=='s'){
      scanf("%d",&key);
      insert(key);
    }
    else if(order[2]=='t'){
      a=extract();
      printf("%d\n",a);
    }
    else if(order[2]=='d'){
      break;
    }
    else{
      printf("miss order!\n");
    }
  }

  return 0;
}

