def extract(i)
  left = i*2
  right = i*2 + 1
  length = A.length

  if left < length && A[left] > A[i]
    @largest = left
  else
    @largest = i
  end

  if right < length && A[right] > A[@largest]
    @largest = right
  end

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

def insert(i)
  parent = i/2
  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 (input=gets.chomp) == "end"
  if input == "extract"
    puts A[1]
    A[1] = A.pop
    extract(1)
  else
    input = input.split(" ")
    A << input[1].to_i
    insert(A.length-1)
  end
end

