import Control.Applicative

main :: IO ()
main = do
    input <- (map read . words) <$> getLine
    let l = lcm (input!!0) (input!!1)
    if l == (input!!0) then
        print (-1)
    else print (input!!0)
