#include <stdio.h>
#define H 2000000

void insert(int);
int extract();
void heapIncreaseKey(int i, int);
void buildMaxHeap(int *);
void maxHeapify(int *, int);
int parent(int);
int left(int);
int right(int);

int size = 1;
int S[H];

int main(){

  int i = 0;
  char com[10];
  int key = 0, dkey = 0;
  
 
  while(1){
    scanf("%s",com);
    //printf("%c\n",com[0]);
    if(com[0] == 'e' && com[1] == 'n')break;
    if(com[0] == 'i'){
      scanf("%d",&key);
      insert(key);
      //printf("fds\n");
    }
    if(com[0] == 'e' && com[1] == 'x'){
      dkey = extract();
      printf("%d\n",dkey);
      //printf("hgf\n");
    }
  }
  
  return 0;
}

void insert(int k){
  size++;
  S[size] = -1;
  heapIncreaseKey(size,k);
}

int extract(){
  int max = 0;
  
  if(size < 1){
    printf("heap underflow\n");
  }
  max = S[1];
  S[1] = S[size--];
  maxHeapify(S, 1);
  return max;
}

void heapIncreaseKey(int i,int key){
  int keep = 0;
  
  if(key < S[i]){
    printf("new key is smaller than current key\n");
  }
  S[i] = key;
  while(i > 1 && S[parent(i)] < S[i]){
    keep = S[i];
    S[i] = S[parent(i)];
    S[parent(i)] = keep;
    i = parent(i);
  }
}

void buildMaxHeap(int *A){
  int i = 0;
  
  for(i = size/2; i >= 1; i--){
    maxHeapify(A,i);
  }
}

void maxHeapify(int *A, int i){
  int l = left(i), r = right(i), largest = 0;
  int keep = 0;

  //left, right and me top of the world
  if(l <= size && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }

  if(r <= size && A[r] > A[largest]){
    largest = r;
  }

  if(largest != i){
    //A[i] koukan A[largest]
    keep = A[i];
    A[i] = A[largest];
    A[largest] = keep;
    maxHeapify(A, largest);
  }
}

int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

