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

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