fun main(args : Array<String>) {
    val (x, y) = readLine()!!.split(" ").map{it.toLong()}
    val lcm = lcm(x, y)

    for (i in x..lcm) {
        if (i % x == 0L && i % y != 0L) {
            println(i)
            return
        }
    }

    println(-1)
}

fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

fun lcm(a : Long, b : Long) : Long {
    return (a * b) / gcd(a, b)
}
