import Data.Char

getDigitSum :: Integer -> Integer
getDigitSum num = fromIntegral . sum $ map (\c -> ord c - ord '0') (show num)

main :: IO ()
main = do
  num <- read <$> getLine :: IO Integer
  let ans = minimum $ map getDigitSum $ zipWith (*) [1..45] $ replicate 45 num
  putStrLn . show $ ans
