main = do [n, m] <- map read . words <$> getLine print $ solve n m solve :: Int -> Int -> Int solve n m | n == m || odd n && n <= m = 1 | even n && n <= 2 * m = 2 | otherwise = -1