Problem:
Score : 100 points

Problem Statement

You are given positive integers X and Y.
If there exists a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, choose one such integer and print it.
If it does not exist, print -1.

Constraints

1 ≤ X,Y ≤ 10^9

X and Y are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print a positive integer not greater than 10^{18} that is a multiple of X but not a multiple of Y, or print -1 if it does not exist.

Sample Input 1

8 6

Sample Output 1

16

For example, 16 is a multiple of 8 but not a multiple of 6.

Sample Input 2

3 3

Sample Output 2

-1

A multiple of 3 is a multiple of 3.

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second
 
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl
 
template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}
 
/************************************************/
#define MN 2000005
 
int fr[MN],nex[MN],vi[MN],tot=0;
int sn[MN];
int n;
int vd[MN];
int tt[MN];
int res;
void add(int x,int y){
	vi[++tot]=y;nex[tot]=fr[x];fr[x]=tot;++sn[x];
}
void dfs(int x,int fa){
	for(int i=fr[x];i;i=nex[i])if(vi[i]!=fa){
		dfs(vi[i],x);
		if(vd[vi[i]])++vd[x];
		tt[x]+=tt[vi[i]];
	}
	if(vd[x]<sn[x]-1){
		res+=sn[x]-1-vd[x];
		tt[x]+=sn[x]-1-vd[x];
		vd[x]=sn[x]-1;
	}
	//cerr<<x<<' '<<sn[x]<<' '<<vd[x]<<' '<<tt[x]<<' '<<res<<endl;
}
int main(){
	read(n);
	if(n==1)return puts("0"),0;
	if(n==2)return puts("1"),0;
	for(int i=2;i<=n;++i)sn[i]=-1;
	for(int i=1,x,y;i<n;++i){
		read(x);read(y);++x;++y;
		add(x,y);add(y,x);
	}
	dfs(1,1);
	for(int i=2;i<=n;++i){
		if(vd[i]==sn[i]-1&&res==tt[i]){++res;break;}
	}
	printf("%d",res);
	return 0;
}