#include<stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 2000000
#define swap(x, y, type) do{type t = x; x = y; y = t;}while(0)

void upheap(int first, int right, int *tab)
{
        int  pare, btn = tab[right],child ;

        for (child = right; child > first; child = pare)
        {
                pare = (child - first + 1) / 2 - 1 + first;
                if (tab[pare] >= btn) break;
                tab[child] = tab[pare];
        }

        tab[child] = btn;
}
void downheap(int first, int left, int right, int *tab)
{
        int child, pare, root = tab[left];

        for (pare = left; pare < (right - first + 1) / 2 + first;
                 pare = child) {
                int l = 2 * pare - first + 1, r = l + 1;
                if (r <= right && tab[r] > tab[l]) {child = r;}
                else {child = l;}
                if (root >= tab[child]){ break;}
                tab[pare] = tab[child];
        }

        tab[pare] = root;
}
void sort(int n, int first, int *a)
{
        int i;
        for (i = (n - first) / 2 - 1 + first; i >= first; i--) {downheap(first, i, n - 1, a);}
        for (i = n - 1; i > first; i--) {
                swap(a[first], a[i], int);
                downheap(first, first, i - 1, a);
        }
}
void delete(int *n, int first, int m, int *a)
{
        int pre = a[m];
        a[m] = a[(*n) - 1];
        (*n)--;
        if (pre > a[m]) {downheap(first, m, (*n) - 1, a);}
        else {upheap(first, m, a);}
}

void insert(int *n, int first, int data, int *a)
{
        (*n)++;
        a[(*n) - 1] = data;
        upheap(first, (*n) - 1, a);
}


main()
{
        int cnt,first,k;
        int a[MAX];
        char cmd[8];
        first=0;
        cnt=0;
        while (1) {
                scanf("%s", cmd);
                if (!strcmp(cmd, "end")) {break;}
                switch (cmd[0]) {
                case 'i':
                        scanf(" %d", &k);
                        insert(&cnt, first, k, a);
                        break;
                case 'e':
                        printf("%d\n", a[first]);
                        delete(&cnt, first , first, a);
                        break;
                }
        }
}

