#include <stdio.h>
#define N 1000000
#define INF -10000000
int A[N], heapSize = 0;

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

void insert(int key) {
  int i;
  heapSize++;
  A[heapSize] = INF;
  i = heapSize;
  heapIncreaseKey(i, key);
}

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

  while(1) {
    l = 2*i;
    r = 2*i+1;
    if(l <= heapSize && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= heapSize && A[r] > A[largest]) largest = r;
    if(largest != i) {
      tmp = A[i];
      A[i] = A[largest];
      A[largest] = tmp;
      i = largest;
    }
    else break;
  }
}

int extract(void) {
  int max;
  if(heapSize < 1) return 0;
  max = A[1];
  A[1] = A[heapSize];
  heapSize--;
  maxHeapify(1);
  return max;
}

int main () {
  char cmd[8];
  int key, i;

  while(1) {
    scanf("%s", cmd);
    if(cmd[0] == 'i') {
      scanf("%d", &key);
      insert(key);
    }
    if(cmd[0] == 'e' && cmd[1] == 'x') printf("%d\n", extract());
    if(cmd[0] == 'e' && cmd[1] == 'n') break;
  }

  return 0;
}