"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let X = xs[0];
   let Y = xs[1];
   let ans = 0;
     if(X%Y==0){
       ans = -1;
     }else{
       ans = X;
     }
    console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));