import java.util.Scanner

/**
  * Created by 80011714 on 2018/2/5.
  */
object Main {

  def solve(sc: Scanner): Unit = {
    val x, y = sc.nextLong()
    println(if (x % y == 0) (-1) else {
      var i = 1
      while (i * x % y == 0) (i += 1)
      i * x
    })
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}
