-- AtCoder My Practice
-- author: Leonardone @ NEETSDKASU

main = getLine
   >>= print
     . (\xs ->
           let len = length xs
           in if len < 2
               then read xs
               else if all (== '9') xs
                     then 9 * len
                     else let h = read $ take 1 xs
                          in (h - 1) + 9 * (len - 1)
       )