import Control.Applicative main :: IO () main = solve <$> f >>= print where f = map read <$> words <$> getLine solve :: [Int] -> Int solve [a, b] = f . divs $ a + b where f [] = -1 f (c:cs) | a /= c && b /= c && (a + c) `mod` b == 0 && (b + c) `mod` a == 0 = c | otherwise = f cs divs :: Int -> [Int] divs n = let (xs, ys) = f [] [] 1 in xs ++ ys where f as bs x | x ^ 2 > n = (reverse as, bs) | n `mod` x == 0 = f (x:as) (n `div` x :bs) (x + 1) | otherwise = f as bs (x + 1)