fun main(args: Array<String>) {
    apc001a()
}

fun apc001a() {
    val (x, y) = readLine()!!.split(' ').map { it.toLong() }

    if (x % y == 0L) return println(-1)

    for (i in x..(1e18).toLong() step x) if (i%y!=0L) return println(i)

    println(-1)
}
