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

main = getLine
   >>= print
     . (\(x:xs) ->
           let len = length xs
           in 9 * len + read [x]
            - if all (== '9') xs
               then 0
               else 1
       )