import Control.Monad
import Control.Applicative
import Data.List

main :: IO ()
main = do
    [x, y] <- fmap read . words <$> getLine :: IO [Int]
    if x `mod` y == 0
        then print (-1)
        else print x