import Control.Applicative ((<$>)) import Data.List main :: IO () main = do solve <$> read <$> getLine >>= print solve :: Int -> Int solve = foldr g 0 . unfoldr f where f x | x == 0 = Nothing | otherwise = Just (let (q, r) = divMod x 7 in (r, q)) g x y = x + 10 * y