import scala.io.StdIn._

object Main {
    def main(args: Array[String]): Unit = {
        val Array(x, y) = readLine.split(" ").map(_.toInt)
        if (y % x == 0) {
            println(-1)
        } else {
            println(f(x, y, 1))
        }
    }
    
    def f(x: Int, y: Int, n: Int): Int = {
        if (x * n >= Math.pow(10, 18) ) {
            -1
        } else if (x * n % y == 0) {
            f(x, y, n + 1)
        } else {
            x * n
        }
    }
}