#include<cmath>
#include<cstdio>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b){
	if (a>b)return gcd(b,a);
	if (a==0) return b;
	return gcd(a,b%a);
}

int main(){
	LL a,b,c;
	scanf("%lld%lld",&a,&b);
	c=gcd(a,b);
	if (c==b){
		printf("-1\n");
		return 0;
	}
	printf("%lld\n",(a*2));
}
