let rec dig_sum x = if x <= 0 then 0 else x mod 10 + dig_sum (x / 10)
let n = Scanf.scanf "%d" (fun x -> x)
let () =
  Array.init (n-1) (fun i ->
    let a, b = i+1, n-1-i in
    dig_sum a + dig_sum b)
  |> Array.fold_left min 1010
  |> Printf.printf "%d\n"
