#include<stdio.h>
#define INF 1000000
#define N 2000000

void insert(int *, int);
void increase(int *, int, int);
int extractmax(int *);
void maxHeapify(int *, int);

int n=0;
int S[N];

int main()
{

  int i=0, k, j, max[N];
  char com[10];


  while(1){
    scanf("%s", com);
    
    if(com[0] == 'i'){
      scanf("%d", &k);
      insert(S, k);
    }

    else if(com[1] == 'x'){
      max[i] = extractmax(S);
      i++;
    }

    else if(com[1] == 'n') break;

  }

  for(j = 0; j < i; j++){
    printf("%d\n", max[j]);
  }

  return 0;

}

void insert(int *S, int k)
{
  n += 1; 
  S[n] = -INF;
  increase(S, n, k);
}

void increase(int *S, int i, int key)
{

  int temp;

  S[i] = key;

  while(i > 1 && S[i/2] < S[i]){
    temp = S[i];
    S[i] = S[i/2];
    S[i/2] = temp;
    i = i/2;
  }
}

int extractmax(int *S)
{
  int max;

  max = S[1];
  S[1] = S[n];
  n--;
  maxHeapify(S, 1);

  return max;
}

void maxHeapify(int *A, int i)
{

  int l, r, largest;
  int temp;

  l = 2*i;
  r = 2*i+1;
  
  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if(l <= n && A[l] > A[i]) largest = l;
  else largest = i;

  if(r <= n && A[r] > A[largest]) largest = r;

  /* iの子の方が値が大きい場合 */
  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(A, largest); // 再帰的に呼び出し
  }
}