#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int X,Y;	
long long ans;
const long long inf = 1e18;
int gcd(int x,int y)
{
	return !y ? x : gcd(y,x%y);
}
int main()
{
	scanf("%d%d",&X,&Y);
	if (gcd(X,Y)==Y) 
	{
		puts("-1");
		return 0;
	}
	ans = 1ll * X * Y / gcd(X,Y);
	while(ans < inf && ans % Y == 0) ans += X;
	while(ans >=inf || ans % Y == 0) ans -= X;
	cout << ans<<endl; 
	return 0;
}