#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
using namespace std;
#define llg long long
#define maxn 150010
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);

inline llg getint()
{
    llg w=0,q=0; char c=getchar();
    while((c<'0' || c>'9') && c!='-') c=getchar();
    if (c=='-')  q=1, c=getchar(); while (c>='0' && c<='9') w=w*10+c-'0', c=getchar();
    return q ? -w : w;
}
int main()
{
	llg a,b;
	cin>>a>>b;
	if (a%b==0) {cout<<-1; return 0;}
	llg x=a;
	while (x%b==0) x+=a;
	cout<<x;
	return 0;
} 
