import Data.Char
import Data.List
import Control.Monad

main :: IO ()
main = readLn >>= print . solve 

solve :: Int -> Int 
solve k = min a b 
    where
        a = foldl' ff 0 $ show k
        b = foldl' ff 0 . show $ 2 * k
        ff acc x = acc + val x
        val x = ord x - ord '0'