import std.stdio, std.range, std.algorithm, std.conv, std.string;
import std.container;

void main()
{
    auto a = Array!(int)();
    auto h = heapify(a);

    foreach (line; stdin.byLine)
    {
        if (line[0..3] == "end")
        {
            break;
        }

        if (line[0..6] == "insert")
        {
            h.insert(line[7..$].chomp.to!int);
        }
        else if (line[0..7] == "extract")
        {
            h.front.writeln;
            h.popFront;
        }
    }
}