#include<iostream>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	if(x%y==0)
		cout<<-1<<endl;
	else
	{
		for(long long i=x+x;i<=1e18;i+=x)
		if(i%y!=0)
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}