#include<stdio.h>
#include<string.h>
#define INFTY (1<<30)
#define MAX 10000000

int p(int i){return i/2;}
int l(int i){return 2*i;}
int r(int i){return 2*i+1;}

void maxHeapify(int *,int );
void swap(int *,int *);
void insert(int *,int );
void heapIncreaseKey(int *,int ,int );
int  extract(int *);

int n;

int main(){
  int key;
  char ob[10];
  int A[MAX];
 
  while(1){
    strcpy(ob,"");
    scanf("%s",ob);
    if(strcmp(ob,"insert")==0){
      scanf("%d",&key);
      insert(A,key);
    }else if(strcmp(ob,"extract")==0){
      printf("%d\n",extract(A));
    }else if(strcmp(ob,"end")==0) break;
  }

  return 0;
}


void maxHeapify(int *A,int i){
  int lft,rgh,max;
  lft=l(i);
  rgh=r(i);

  if(lft <= n && A[lft]>A[i]) max=lft;
  else max=i;
  if(rgh <=n && A[rgh]>A[max]) max=rgh;

  if(max!=i){
    swap(&A[max],&A[i]);
    maxHeapify(A,max);
  }
}

void swap(int *a,int *b){
  int buf;
  buf=*a;
  *a=*b;
  *b=buf;
}

void heapIncreaseKey(int *A,int i,int key){
  if(key<A[i]) return ;
  A[i]=key;
  while(i>1 && A[p(i)]<A[i]){
    swap(&A[p(i)],&A[i]);
    i=p(i);
  }
}

void insert(int *A,int key){
  n++;
  A[n]=-INFTY;
  heapIncreaseKey(A,n,key);
}

int extract(int *A){
  int max;
  if(n<1) return -INFTY;
  max=A[1];
  A[1]=A[n--];
  maxHeapify(A,1);
  return max;
}

