import Data.Ratio mod2And5 :: Integral a => a -> a mod2And5 x | mod x 2 == 0 = mod2And5 (div x 2) | mod x 5 == 0 = mod2And5 (div x 5) | otherwise = x solve :: (Read a, Show a, Integral a) => a -> a -> a solve n d | mod2And5 d' > 1 = -1 | otherwise = read . (: "") . last . reverse . dropWhile (== '0') . reverse . show $ t where d' = denominator $ n % d t = solve2 n d solve2 :: Integral a => a -> a -> a solve2 n d | mod n d == 0 = div n d | otherwise = solve2 n' d where n' = (n - d * (div n d)) * 10 main = do n <- readLn m <- readLn print $ solve n m