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 (px, py) = (9, d - 2)
    let (qx, qy) = (f1 - 1, d - 1)
    let a0 = foldr (\c a -> digitToInt c + a) 0 (show n)
    let a1 = foldr (\c a -> digitToInt c + a) 0 (show px ++ replicate py '9')
    let a2 = foldr (\c a -> digitToInt c + a) 0 (show qx ++ replicate qy '9')
    if n < 10
        then print n
        else print $ maximum [a0, a1, a2]