import Control.Applicative 
import Data.Char

getMax :: String -> Int
getMax (a:rest) =
    let figure = (length (a:rest)) - 1 
        top = (digitToInt $ a)
        ismax = all (\a -> a == '9') rest
        in if ismax then (figure * 9 + top) else (figure * 9 + (top - 1))
        

main = print =<< getMax <$> getLine
