#include <stdio.h>

int H[2000005],n=0;

void max(int x)
{
    int l,r,largest,d;
    l=2*x;
    r=l+1;

    if( l <= n && H[l] > H[x] ) 
        largest = l;
    else
        largest = x;
    if( r <= n && H[r] > H[largest] )
        largest = r;
   
    if( largest != x ) {
        d=H[largest];
        H[largest]=H[x];
        H[x]=d;
        max(largest);   
    }
}

int extract(void)
{
    int m;
    m=H[1];
    H[1]=H[n];
    n--;
    max(1);

    return m;
}

void increse(int x,int key)
{
    int d;
    if (key<H[x])
        return;
    H[x]=key;
    while(x>1&&H[x]>H[x/2])
    {
        d=H[x];
        H[x]=H[x/2];
        H[x/2]=d;
        x= x/2;
    }
}

void insert(int key)
{
    n++;
    H[n]=-2000005;
    increse(n,key);
}

int main()
{
    int key;
    char comand[10];

    while(1)
    {
        scanf("%s",comand);

        if (comand[0]=='e'&&comand[1]=='n') break;
        else if (comand[0]=='i')
        {
            scanf("%d",&key);
            insert(key);
        }
        else
        {
            printf("%d\n",extract());
        }

    }

    return 0;
}  
