sumOfDigitp :: Int -> Int -> Int
sumOfDigitp total 0 = total
sumOfDigitp total n = sumOfDigitp (total + r) q
  where
    q = n `div` 10
    r = n `mod` 10

sumOfDigit :: Int -> Int
sumOfDigit = sumOfDigitp 0

func :: Int -> Int -> Int -> Int
func minN i n
  | i > (n `div` 2) = minN
  | otherwise = func minNp (i + 1) n
  where
    minNp = min minN $ (+) (sumOfDigit i) (sumOfDigit (n-i))

main = do
  line <- getLine
  let
    n = read line :: Int
    ans = func 1000 1 n
  putStrLn $ show ans
