function Main(input) {
	input = input.split(" ").map(Number);
	if(input[0]%input[1]==0){
		console.log(-1)
	}else{
		console.log(input[0])
	}
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());