let rec f z m e =
  let zzz = z*z*z in
  if zzz > e then m
  else
    let y = truncate (sqrt (float (e - zzz))) in
    let x = e - (y*y + zzz) in
    let mm = min m (x+y+z) in
    f (z+1) mm e

let rec solve () =
  match read_int () with
  | 0 -> exit 0
  | e ->
    print_int (f 0 e e); print_newline ();
    solve ()

let () = solve ()