void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.exception;

  long x, y; rd(x, y);

  if(x==y) writeln(-1);
  else if(x<y) writeln(x);
  else writeln(x%y==0 ? -1 : x);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}