#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int t[2000000],n=1;

void maxheapify(int i){
  int l=2*i,r=2*i+1,large,v;
  if(l<=n&&t[l]>t[i])large=l;
  else large=i;
  if(r<=n&&t[r]>t[large])large=r;
  if(large!=i){
    v=t[i];
    t[i]=t[large];
    t[large]=v;
    maxheapify(large);
  }
}

int main(){
  int i,j,v;
  char s[8];
while(1){
  scanf("%s",s);
  if(strcmp(s,"insert")==0){
    scanf("%d",&t[n]);
    j=n;
    for(i=n/2;i>=1;i=i/2){
        if(t[i]<t[j]){
          v=t[i];
          t[i]=t[j];
          t[j]=v;
          j=i;
        }
    }
    n++;
  }
  else if (strcmp(s,"extract")==0){
    printf("%d\n",t[1]);
    t[1]=t[n-1];
    n--;
    maxheapify(1);
  }
  else if(strcmp(s,"end")==0)break;
}
  return 0;
}
    


