import Control.Applicative
import Control.Monad
import Data.List
import Data.Char (digitToInt)

main :: IO ()
main = do
    n <- readLn :: IO Int
    let d = length (show n)
    let f1 = read [head $ show n] :: Int
    let (a, b) = if f1 == 1
                 then (9, d - 2)
                 else (f1 - 1, d - 1)
    if n < 10
        then print n
        else print $ foldr (\c a -> digitToInt c + a) 0 (show a ++ replicate b '9')