import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val (x, y) = br.readLine().split(' ').map { it.toInt() }
    if (x % y == 0) {
        println("-1")

    } else {
        println(x)
    }
}

fun err(print: Any) {
    System.err.println(print)
}