main = interact (show . solve . read)

solve :: Int -> Int
solve n = n `mod` 9 + solve' (n `div` 9)

solve' 0 = 0
solve' n =
    let
        p = n `mod` 9
        q = p `div` 4 + p `mod` 4
    in
    q + solve' (n `div` 9)

