#include<stdio.h>
#define max	1000000000000000000
int main()
{
	long long x,y,z;
	scanf("%lld%lld",&x,&y);
	z=x+x;
	if(x==y||x%y==0)
	{
		printf("-1\n");
		return 0;
	 } 
	while(z<=max&&z>=1&&(((z%y))==0))
	{
		z+=x;
	}
	if(z<=max&&z>=1&&((z%y)==0))
		printf("%lld\n",z);
	else 
		printf("-1\n");

	return 0;
}
//x*z这个数%y！=0 