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

        #define N 2000002
        #define M 10

        int NUM = 0;

        void Defma(int *t, int i){

            int left, right;
            int  large, c;

            if( i * 2 + 1 < NUM + 1) right = i * 2 + 1;
            else right = i;

            if( i * 2 < NUM + 1)
                left = i * 2;
            else left = i;

            if(left <= NUM && t[left] > t[i])
                large = left;
            else large = i;

            if(right <= NUM && t[right] > t[large])
                large = right;

            if(large != i){
                c = t[i];
                t[i] = t[large];
                t[large] = c;

                Defma(t, large);
            }
        }

        void Defin(int *arrayt, int z){

            int i,c;

            NUM++;
            i = NUM;
            arrayt[NUM] = z;

            while(i > 1 && arrayt[i/2] < arrayt[i]){

                c = arrayt[i];

                arrayt[i] = arrayt[i/2];

                arrayt[i/2] = c;


                i /= 2;
            }
        }

        void Defex(int *arrayt){

            printf("%d\n", arrayt[1]);

            if(NUM > 1) arrayt[1] = arrayt[NUM];

            NUM--;

            if(NUM > 1) Defma(arrayt, 1);
        }

        int main(){

            int i;
            int AI[N];
            char AC[M];

            while(1){

                scanf("%s", AC);

                if(AC[2] == 'd') break;
                else if(AC[0] == 'i'){
                    scanf("%d", &AI[0]);
                    Defin(AI, AI[0]);
                }

                
                else Defex(AI);
            }

            return 0;
        }

