main = interact $ unlines . map (show . coconut_grab . read) . init . lines
 
coconut_grab e = minimum cands
 where
  cands = [x+y+z | let z' = last $ takeWhile ((<=e).(^3)) [0..], z<-[0..z'],
                   let y' = last $ takeWhile ((<=e-z^3).(^2)) [0..], y<-[0..y'],
                   let x = e-z^3-y^2]