
import Control.Applicative
import Data.List
import Data.Char

getInt :: IO Integer
getInt = (\a -> read a :: Integer) <$> getLine

getIntArray :: IO [Integer]
getIntArray = ((map (\a -> read a :: Integer)) . words) <$> getLine

getStrArray :: Integer -> IO [String]
getStrArray 0 = return [] :: IO [String]
getStrArray n = (:) <$> getLine <*> (getStrArray (n - 1))

ans :: [Integer] -> Integer
ans [x, y]
    | mod x y == 0 = -1
    | otherwise = x + lcm x y

main = do
    inp <- getIntArray
    print $ ans inp
