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

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