def extract(i)
  l = 2*i -1
  r = 2*i
  i -= 1

  if A[l] == nil
    return
  elsif A[r] == nil 
    A[i], A[l] = A[l], A[i]
  elsif A[l] > A[r] && A[l] > A[i]
    A[i], A[l] = A[l], A[i]
    extract(l+1)
  elsif A[l] < A[r] && A[r] > A[i]
    A[i], A[r] = A[r], A[i]
    extract(r+1)
  end
end

def insert(i)
  if i == 1
    return
  end

  parent = i/2 -1
  i -= 1

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

A = Array.new

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

