import Data.Char (digitToInt) digits :: String -> [Int] digits n = let m = map digitToInt n in filter (flip elem m) [0 .. 9] solve :: String -> Integer solve s = gcd n $ fromIntegral (foldr gcd 0 [abs (x - y) * 9 | x <- ds, y <- ds]) where n = read s :: Integer ds = digits s main :: IO () main = getLine >>= print . solve