#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>

void Merge(long *A, long left, long mid, long right) {
  long n1,n2,*L,*R,i,j,k;
  n1 = mid -left;
  n2 = right - mid;
  L = (long*)malloc(sizeof(long) * (n1+1));
  R = (long*)malloc(sizeof(long) * (n2+1));
  for (i = 0; i< n1; i++) {
    L[i] = A[left+i];
  }
  for (i = 0; i < n2; i++) {
    R[i] = A[mid+i];
  }
  L[n1] = LONG_MAX; R[n2] = LONG_MAX;
  i = 0;j = 0;
  for(k = left; k < right; k++) {
    if (L[i] < R[j]) {
      A[k] = L[i];
      i++;
    }else {
      A[k] = R[j];
      j++;
    }
  }
  free(L);
  free(R);
}

void Merge_Sort(long *A, long left, long right) {
  if(left+1 < right) {
    long mid = (left + right)/2;
    Merge_Sort(A,left,mid);
    Merge_Sort(A,mid,right);
    Merge(A,left,mid,right);
  }
}


int main()
{
  long i,j,k,t,**S,*length,max,maxj;
  char command[8];
  S = (long**)malloc(sizeof(long) * 2000000);
  length = (long*)malloc(sizeof(long) * 2000000);
  j = 0;t = 1;
  while(1) {
    scanf("%s",command);
    if(strcmp(command,"insert") == 0) {
      if(t == 1) {
	S[j] = (long*)malloc(sizeof(long) * (2000000));
	i = 0;
      }
      scanf("%ld",S[j]+i);
      i++;
      t = 0;
    }
    if(strcmp(command,"extract") == 0) {
      if(t == 0) {
	Merge_Sort(S[j],0,i);
	length[j] = i;
	j++;
      }
      max = 0;
      for(k = 0; k < j; k++) {
	if(S[k] != NULL && S[k][length[k]-1] > max) {
	  max = S[k][length[k]-1];
	  maxj = k;
	}
      }
      length[maxj]--;
      if(length[maxj] == 0) {
	free(S[maxj]);
	S[maxj] = NULL;
      }
      printf("%ld\n",max);
      t = 1;
    }
    if(strcmp(command,"end") == 0) break;
  }
  return 0;
}