import           Data.Char

main :: IO ()
main = do
    n <- map digitToInt <$> getLine
    print $ solve n 

solve :: [Int] -> Int
solve (x:xs)
    | all (== 9) xs = x + 9 * length xs
    | otherwise = x + 9 * length xs - 1
