let n = read_int ()
let rec f n = if n < 10 then 0 else if n mod 10 = 9 then f (n / 10) else -1
let rec g s n b = if n < 10 then s + n + b else g (s + if b = -1 then 9 else n mod 10) (n / 10) b
let _ = Printf.printf "%d\n" @@ g 0 n @@ f n