object test {

  def func(a: Long, b: Long): Long = {
    var result = a * 2
    while(true) {
      if (result % b != 0)
        return result
      result += a
    }
    return -1
  }

  def main(args: Array[String]): Unit = {
    val context = Console.readLine()
    val numbers = context.split(" ").map(_.toLong)

    if (numbers(1) % numbers(0) == 0) {
      println("-1")
    } else {
      println(func(numbers(0), numbers(1)))
    }
  }
}