def parent(i)
  i/2
end

def left(i)
  i*2
end

def right(i)
  i*2 + 1
end

def extract(i)
  l = left(i)
  r = right(i)
  h = A.length

  # printf "extract %d\n",i
  # p A
  # printf "l %d  r %d  h %d\n",l,r,h

  if l < h && A[l] > A[i]
    @largest = l
  else
    @largest = i
  end

  if r < h && A[r] > A[@largest]
    @largest = r
  end

  if @largest != i
    A[i], A[@largest] = A[@largest], A[i]
    extract(@largest)
  end
end

def insert(i)
  @parent = parent(i)
  if @parent == 0
    return
  end

  if A[i] > A[@parent]
    A[i], A[@parent] = A[@parent], A[i]
    insert(@parent)
  end
end

A = Array.new
A << 0

until (str=gets.chomp) == "end"
  # p A
  if str == "extract"
    puts A[1]
    A[1] = A.pop
    extract(1)
  else
    str = str.split(" ")
    A << str[1].to_i
    insert(A.length-1)
  end
end

