#include<stdio.h> 
 #include<limits.h> 
   
 
int A[2000000]; 
int n; 
 
int parent(int i) 
{ 
  return i/2; 
}  
int left(int i) 
{ 
   return 2*i; 
} 
 
int right(int i) 
{ 
   return 2*i+1; 
}  
 
 
void maxHeapify(int i) 
{ 
  int l = left(i); 
  int r = right(i); 
  int largest,temp; 
  if( l <= n && A[l] > A[i]) 
    { 
      largest = l; 
    } 
  else 
    { 
      largest = i; 
    } 
  if(r <= n && A[r] > A[largest]) 
    { 
      largest = r; 
    } 
  if (largest != i) 
    { 
      temp = A[i]; 
      A[i] = A[largest]; 
      A[largest] = temp; 
      maxHeapify(largest); 
    } 
} 
 
void buildMaxHeap() 
{ 
  int i; 
  for( i = n/2;i>0;i--) 
    { 
      maxHeapify(i); 
    } 
} 
 
void maxHeapInsert(int key) 
{ 
  n = n + 1; 
  A[n] = INT_MIN; 
  heapIncreaseKey(n,key); 
} 
 
void heapIncreaseKey(int i,int key) 
{ 
  int tmp; 
  if (key < A[i]) 
    { 
      return; 
    } 
  A[i] = key; 
  while (i > 1 && A[parent(i)] < A[i]) 
    { 
      tmp = A[i]; 
      A[i] = A[parent(i)]; 
      A[parent(i)]= tmp; 
      i = parent(i); 
    } 
} 
 
int heapExtractMax() 
{ 
  int max; 
  if ( n < 1) 
    { 
      return; 
    } 
  max = A[1]; 
  A[1] = A[n]; 
  n = n - 1; 
  maxHeapify(1); 
  return max; 
} 
 
 
int main() 
{ 
  int t; 
  char s[10]; 
  while(1){ 
    scanf("%s",s); 
    if(s[2]=='s') 
      { 
scanf("%d",&t); 
maxHeapInsert(t); 
      } 
    if(s[2]=='t') 
      { 
printf("%d\n",heapExtractMax()); 
      } 
    if(s[2]=='d') 
      { 
break; 
      } 
  } 
  return 0; 
} 
