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

//operation of pushing or popping
void maxHeapInsert( int A[], int key );
void heapIncreaseKey( int A[], int, int key );
int  heapExtractMax( int A[] );

//make a max heap 
void swap( int*, int* );
void maxHeapify( int A[], int i );
void buildMaxHeap( int A[] );

//declare sevaral global variables
int n = 0;

int main(){
    int A[N+1], i, j, data;
    char com[10];

    //input and some procedures
    while( 1 ){
	scanf("%s", com);
	if( com[0] == 'i' ){
	    scanf("%d", &data);
	    maxHeapInsert(A, data);
	}
	else if( com[0] == 'e' && com[1] == 'x' ){
	    data = heapExtractMax(A);
	    printf("%d\n", data);
	}
	else break;//when end command was inputted
    }
    return 0;
}

//----------------------------------------------------------------
inline void swap( int* a, int *b ){
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
    return;
}
void maxHeapify( int A[], int p ){
    int l, r, largest;

    //initialize
    l = 2*p;
    r = 2*p + 1;
    //compare those values of p , l and r
    largest = p;
    if( A[l] > A[p] && l <= n ) largest = l;
    if( A[r] > A[largest] && r <= n ) largest = r;
    //swap those values
    if( largest != p ){
	swap( &A[largest], &A[p] );
	maxHeapify( A, largest );
    }
    return ;
}
void buildMaxHeap( int A[] ){
    int l, p, r, i, heap_size = N;

    for( i=N/2; i>=1; i-- ) maxHeapify( A, i );
    
    return ;
}

//------------------------------------------------------------------
void maxHeapInsert( int A[], int key ){

    n += 1;
    A[n] = -INF;
    heapIncreaseKey( A, n, key );

    return ;
}

void heapIncreaseKey( int A[], int i, int key ){
    int p = i/2;

    A[i] = key;
    while( i>1 && A[i] > A[p] ){
	swap( &A[i], &A[p] );
	i = p;
	p = p/2;
    }
    return ;
}

//------------------------------------------------------------------
int heapExtractMax( int A[] ){
    int max, heap_size = n;

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

    return max;
}

