#include<stdio.h>
#include<limits.h>
#define N 2000000
int heap_size;
int A[N];

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
} 
int right(int i){
  return 2*i+1;
}
void heapIncreaseKey(int i, int key){
  int temp;
  if(key < A[i]){
    printf("新しいキーは現在のキーより小さい\n");
  }
  A[i] = key;
  while( i > 1 && A[parent(i)] < A[i]){
    temp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = temp;
    i = parent(i);
  }
}
void maxHeapInsert(int key){
  heap_size = heap_size + 1;
  A[heap_size] = INT_MIN;
  heapIncreaseKey(heap_size,key);
}


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

  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){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
}

int heapExtractMax(){
  int max;
  if(heap_size < 1){
    return 0;
  }
  max = A[1];
  A[1] = A[heap_size];
  heap_size = heap_size - 1;
  maxHeapify(1);
  return max;
}

int main(){
  char M[10];
  int n;
  while(1){
    scanf("%s",M);
    if(M[2] == 'd'){
      break;
    }
    else if(M[2] == 's'){
      scanf("%d",&n);
      maxHeapInsert(n);
      
    }
    else if(M[2] == 't'){
      printf("%d\n",heapExtractMax());
    }
  }
}