arr = Array.new(1_000_001, nil)
for x in 0..1000
    for y in 0..1000
        break if x + y ** 2 >= 1_000_001
        for z in 0..1000
            e = x + y ** 2 + z ** 3
            break if e >= 1_000_001
            arr[e] = x + y + z if arr[e].nil? || arr[e] > x + y + z
        end
    end
end

while true
    e = gets.to_i
    break if e == 0
    puts arr[e]
end
