while true
    e=gets.to_i
    if e==0
        break
    end
    ret=e
    for z in 0...(e**1/3)+1
        ee=e-z**3
        for y in 0...(ee**1/2)+1
            x=ee-y**2
            if x<0
                next
            end
            ret=[ret,x+y+z].min
        end
    end
    puts ret
end