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