#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define NIL -1

int heap_size;

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

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

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

void swap(int *a, int *b){
  int temp;

  temp = *a;
  *a = *b;
  *b = temp;

}

void maxHeapify(int *A, int i){
  int l, r, largest;

  l = left(i);
  r = right(i);

  if(l <= heap_size && A[l] > A[i]){
    largest = l;
  }else{
    largest = i;
  }

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

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

void buildMaxHeap(int *A){
  int i;

  for(i = heap_size/2; i > 0; i--){
    maxHeapify(A, i);
  }

}

void heapIncreaseKey(int *A, int i, int key){

  if(key < A[i]){
    printf("output error in heapIncreaseKey\n");
  }

  A[i] = key;

  while(i > 1 && A[parent(i)] < A[i]){
    swap(&A[i], &A[parent(i)]);
    i = parent(i);
  }

}

void maxHeapInsert(int *A, int key){
  heap_size = heap_size+1;
  A[heap_size] = NIL;
  heapIncreaseKey(A, heap_size, key);
}

int HeapExtractMax(int *A){

  int max;

  if(heap_size < 1){
    printf("output error in HeapExtractMax\n");
  }

  max = A[1];
  A[1] = A[heap_size];
  heap_size--;
  maxHeapify(A, 1);

  return max;
}


int main(){
  int i, k;
  int A[2000000];
  char s[10];

  scanf("%s", s);
  
  while(strcmp(s, "end") != 0){

    if(strcmp(s, "insert") == 0){
      scanf("%d", &k);
      maxHeapInsert(A, k);
    }else{
      printf("%d\n", HeapExtractMax(A));
    }  

    scanf("%s", s);

  }

  return 0;
}