#include <stdio.h>
#define MAX 2000001

int A[MAX], H=0;
void maxHeapify(int);
int heapExtractMax(void);
void heapIncreaseKey(int, int);
void maxHeapInsert(int);


int main() {
  char com[8];
  int x;
  
  while ( 1 ) {
    scanf( "%s" , com );
    if ( com[0] == 'i' ) {
      scanf( "%d" , &x );
      maxHeapInsert(x);
    }
    else if ( com[2] == 't' ) {
      printf( "%d\n" , heapExtractMax() );
    }
    else if ( com[2] == 'd' ) break;
    else continue;
  }
    
  return 0;
}


void maxHeapify(int i) {
  int temp, l, r, largest;
  
  l = i*2;
  r = i*2+1;

  // ���̎q�A�����A�E�̎q�Œl���ő��̃m�[�h���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 ) { // i �̎q�̕����l���傫���ꍇ
    temp = A[i];
    A[i] =  A[largest];
    A[largest] = temp;
    maxHeapify(largest); // �ċA�I�ɌĂяo��
  }
}

int heapExtractMax(void) {
  int max;

  if ( H < 1 ) return 0;
  max = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(1);
  
  return max;
}

void heapIncreaseKey(int i, int key) {
  int temp;
  if ( key < A[i] ) return;
  A[i] = key;
  while ( (i > 1) && (A[i/2] < A[i]) ) {
    temp = A[i];
    A[i] = A[i/2];
    A[i/2] = temp;
    i = i/2;
  }
}

void maxHeapInsert(int key) {
  H++;
  A[H] = -1;
  heapIncreaseKey(H, key);
}

