#include<stdio.h>

int h,A[2000000];

void maxheapify(int A[],int i){
  int l,r,largest,tmp;

  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){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;

    maxheapify(A,largest);
  }
}

void increkey(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;
  }
}

void insert(int A[],int key){
  h=h+1;
  increkey(A,h,key);
}

int extract(int A[]){
  int max;

  max=A[1];
  A[1]=A[h];
  h--;
  maxheapify(A,1);
  return max;
}

int main(){

  int key;
  char o[20];

  while(1){
    scanf("%s",o);
    if(o[2]=='d') break;

    if(o[2]=='s') {
      scanf("%d",&key);
      insert(A,key);
    }

    if(o[2]=='t') printf("%d\n",extract(A));
  }

  return 0;
}

