import std.stdio;
import std.conv;
import std.numeric;
import std.string;

void main()
{
    ulong[] input = readln.split.to!(ulong[]);
    ulong x = input[0];
    ulong y = input[1];

    if (x == y){
        writeln(-1);
        return;
    }
    if (x % y == 0){
        writeln(-1);
        return;
    }
    if (x < y){
        writeln(x);
        return;
    }

    ulong ans = x * gcd(x, y);
    if (ans <= 1000000000000000000)
        writeln(ans);
    else
        writeln(-1);
}
