main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      print $ solve n
      main


solve :: Int -> Int
solve n = fix $ to8 n
  where
    to8 :: Int -> Int
    to8 0 = 0
    to8 n = (n `mod` 8) + 10 * (to8 (n `div` 8))
    fix :: Int -> Int
    fix n = (read . fix') (show n)
      where
        fix' :: String -> String
        fix' [] = []
        fix' (x:xs)
          | x == '4' = '5':(fix' xs)
          | x == '5' = '7':(fix' xs)
          | x == '6' = '8':(fix' xs)
          | x == '7' = '9':(fix' xs)
          | otherwise = x:(fix' xs)