#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
typedef long long int ll;
using namespace std;
#define INF 1234567890
ll x, y;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> x >> y;
ll ans;
if (x%y == 0) {
cout << -1;
}
else {
cout << x;
}
}