#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define INF 2000000000

int parent(int);
int left(int);
int right(int);
void maxheapify(int);
void maxheapinsert(int);
void heapincreasekey(int,int);
int heapextractmax(void);


int A[1000000];
int H=0;

int main(){
  int i;
  int key;
  char order[10];
  
  while(1){
    scanf("%s",order);
    if(strcmp(order,"insert")==0){
      scanf("%d",&key);
      maxheapinsert(key);
    }
    if(strcmp(order,"extract")==0){
      printf("%d\n",heapextractmax());
    }
    if(strcmp(order,"end")==0){
      break;
    }
  }
  return 0;
}
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return (2*i+1);
}
void maxheapify(int i){
  int l,r;
  int swap,largest;
  l=left(i);
  r=right(i);
  if(l<=H && A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap=A[i];
    A[i]=A[largest];
    A[largest]=swap;
    maxheapify(largest);
  }
}
void maxheapinsert(int key){
  H++;
  A[H]=-INF;
  heapincreasekey(H,key);
}
void heapincreasekey(int i,int key){
  int swap;
  if(key<A[i]) printf("new key is smaller than current key\n");
  A[i]=key;
  while(i>1 && A[parent(i)]<A[i]){
    swap=A[i];
    A[i]=A[parent(i)];
    A[parent(i)]=swap;
    i=parent(i);
  }
}
int heapextractmax(void){
  int max;
  if(H<1) printf("heap underflow\n");
  max=A[1];
  A[1]=A[H];
  H--;
  maxheapify(1);
  return max;
}

