#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

int main() {
    LL x, y;
    
    cin >> x >> y;
    
    if (x % y == 0) puts("-1");
    else printf("%lld\n", x * (y - 1));
    
    return 0;
}