#include<stdio.h>

int A[200000];
int place = 0;

void maxH(int);

int main(){

  int i;

  char c[10];

  while(1){
    
    scanf("%s",c);
    if(c[0] == 'i'){
      place++;
      scanf("%d",&A[place]);
    }
    else if(c[1] == 'x'){
      for(i=place/2;i>=1;i--){
	maxH(i);
      }
      printf("%d\n",A[1]);
      A[1] = A[place];
      place--;
    }
    
    else if(c[0]=='e')break;
  }

  return 0;
}

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

  l = 2*i;
  if(l<=place&&A[l]>A[i])
    largest = l;
  else largest = i;
  
  if(place>2*i){
    r = 2*i+1;
    if(A[r]>A[largest])largest = r;
  }

  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
  }
}