#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define pdd pair<double,double>
using namespace std;
int main(){
    long long x,y;
    scanf("%lld%lld",&x,&y);
    if(x%y==0)printf("-1\n");
    else printf("%lld\n",x);
    return 0;
}
/*
1 1 2 2
2
2 0 1
1 1 1
*/
