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

main = interact
     $ (++ "\n")
     . show
     . \(x:xs) ->
           9 * length xs + read [x]
         - if all (== '9') xs
            then 0
            else 1
