Printf.printf "%d\n" @@ Scanf.scanf "%s" @@ fun s ->
  let t = Array.init (String.length s) (fun i -> s.[i]) in
  let x = Array.fold_left (fun z c -> z + (int_of_char c - 48) mod 10) 0 t in
  (int_of_char s.[0] - 49) + (9 * (String.length s - 1)) |> max x