import Data.Char

main = do
  n <- getLine

  print $ maximum $ map (sum . map (\c -> ord c - ord '0')) (solve [] n)

  where
    solve pre [] = [pre]
    solve pre (x:xs) = (pre ++ (chr (ord x - 1) : map (const '9') xs)) : solve (pre++[x])xs
