#include<stdio.h>
#include<string.h>
#define Max 2000000
#define INFTY 1
int heap ;
int A[Max+1];
void MaxHeapify(int);
void swap(int *,int *);
int extract();
void increaseKey(int ,int);
void insert(int);
int main(){
  int key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(strcmp(com,"end")==0)break;
    if(strcmp(com,"insert")==0){
      scanf("%d",&key);
      insert(key);
    }
    else{
      printf("%d\n",extract());
    }
  }
  return 0;
}

void MaxHeapify(int x){
  int left,right,maximum;
  left=2*x;
  right=2*x+1;
  if(left<=heap&&A[left]>A[x])maximum=left;
  else maximum=x;
  if(right<=heap&&A[right]>A[maximum])maximum=right;

  if(maximum !=x){
    swap(&A[x],&A[maximum]);
    MaxHeapify(maximum);
  }
}

void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
int extract(){
  int maxv;
  if(heap<1)return -INFTY;
  maxv=A[1];
  A[1]=A[heap--];
  MaxHeapify(1);
  return maxv;
}
void increaseKey(int i,int key){
  int half;
  if(key<A[i])return ;
  A[i]=key;
  while(i>1&& A[i/2]<A[i]){
    swap(&A[i],&A[i/2]);
    i=i/2;
  }
}
void insert(int key){
  heap++;
  A[heap]=-INFTY;
  increaseKey(heap,key);
}