let rec digits_sum = function
  | 0 -> 0
  | n -> n mod 10 + digits_sum (n / 10)

let () = Scanf.scanf "%d" @@ fun n ->
  Array.init (n - 1) (fun a -> a + 1, n - a - 1)
  |> Array.map (fun (a, b) -> digits_sum a + digits_sum b)
  |> Array.fold_left min max_int
  |> Printf.printf "%d\n"