const Debug = function () {
    const stdin = function (text) {
        return '123 6';

    };

    return stdin;
};


const Release = function () {
    const fs = require('fs');
    const stdin = function (text) {
        if (text) console.log(text);
        return fs.readFileSync('/dev/stdin', 'utf8');
    }
    return stdin;
};


const debug = false;

const stdin = debug ? Debug() : Release();
const input = stdin().split(' ').map(x => parseInt(x));

const X = input[0];
const Y = input[1];

const primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29];//, 31, 37];//, 41, 43, 47];
if (X % Y === 0) console.log(-1);
else {
    var h = true;
    for (var i = 0; i < primes.length; i++) {
        var x = X * primes[i];
        if (x > 1000000000000000000) {
            console.log(-1);
            h = false;
            break;
        } else {
            if (x % Y !== 0) {
                console.log(x);
                h = false;
                break;
            }
        }
    }
    if (h) console.log(-1);
}