let sumdigit n =
  let rec sumd c n' len =
    if n' / 10 = 0 then (c+n', n', len)
    else sumd (c+(n' mod 10)) (n'/10) (len+1)
  in
  sumd 0 n 0
;;

let ()=
  let n = Scanf.scanf "%d\n" (fun x ->x) in
  let sumd, hd, len = sumdigit n in
  let sum9 = len*9 + (hd-1) in
  let ans = if sumd > sum9 then sumd else sum9 in
  print_int ans
;;