let rec yy y z m e =
  let x = e - (y*y + z*z*z) in
  if x >= 0 then yy (y+1) z (min m (x+y+z)) e else m

let rec zzz z m e =
  if z*z*z <= e then zzz (z+1) (yy 0 z m e) e else m

let rec solve () =
  let e = read_int () in
  if e == 0 then exit 0
  else print_int (zzz 0 e e); print_newline (); solve ()

let () =
  solve ()