function Main(input) {
	input = input.trim().split(" ").map((a)=>Number(a));
  var A = input[0];
  var B = input[1];
  if(A % B != 0){
     console.log(A);
  }else{
   	console.log(-1); 
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
