import qualified Data.Char as Ch

f "" ln = 0
f (c:cs) ln
   | d == 0 = d + f cs (ln - 1)
   | otherwise = max (d + f cs (ln - 1)) ((ln - 1) * 9 + d - 1)
   where d = Ch.ord c - Ch.ord '0'

main = do
   inp <- getLine
   let ln = length inp in print $ f inp ln
