#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

#define REP(i,n) for(Int i=0;i<(n);i++)
#define RREP(i,n) for(Int i=(n)-1;i>=0;i--)
#define FOR(i,a,b) for(Int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(Int i=(b)-1;i>=(a);i--)
#define STRS(i,str) for(Int i=0;(str)[i];i++)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAXI(a,b) (((a)==-1||(b)==-1)?-1:MAX((a),(b)))
#define MINI(a,b) ((a)==-1?(b):(b)==-1?(a):MIN((a),(b)))
#define MAX3(a,b,c) ((a)>(b)?(a)>(c)?(a):(c):(b)>(c)?(b):(c))
#define MIN3(a,b,c) ((a)<(b)?(a)<(c)?(a):(c):(b)<(c)?(b):(c))
#define MED(a,b,c) ((a)<(b)?(a)>(c)?(a):(b)<(c)?(b):(c):(a)>(c)?(b)<(c)?(c):(b):(a))
#define RANGE(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define RANGE3(a,b,c) ((a)>(b)?(b)>(c)?(a)-(c):(c)>(a)?(c)-(b):(a)-(b):(b)>(c)?(c)>(a)?(b)-(a):(b)-(c):(c)-(a))
#define MAXS(a,b) if(a<(b))a=(b)
#define MINS(a,b) if(a>(b))a=(b)
#define MAXSI(a,b) if(a!=-1&&((b)==-1||a<(b)))a=(b)
#define MINSI(a,b) if((a)==-1||(b)!=-1&&a>(b))a=(b)
#define BEGINFOR(a,b,c,d,e,f,g,h,i) a;goto i##_6;i##_2:c;goto i##_6;i##_3:h;goto i##_7;i##_4:d;goto i##_8;i##_5:f;goto i##_8;i##_6:if(b)goto i##_4;else goto i##_9;i##_7:if(g)goto i##_5;else goto i##_1;i##_8:if(e)goto i##_2;else goto i##_3;i##_9:
#define CONTINUE(i) goto i##_3
#define BREAK(i) goto i##_1
#define ENDFOR(i) goto i##_3;i##_1:

template<class T> inline T max(T a, T b) { return a > b ? a : b; }
template<class T> inline T min(T a, T b) { return a < b ? a : b; }
template<class T> inline T max(T a, T b, T c) { return a > b ? a > c ? a : c : b > c ? b : c; }
template<class T> inline T min(T a, T b, T c) { return a < b ? a < c ? a : c : b < c ? b : c; }
template<class T> inline T med(T a, T b, T c) { return a < b ? a > c ? a : b < c ? b : c : a > c ? b < c ? c : b : a; }
template<class T> inline T rng(T a, T b) { return a > b ? a - b : b - a; }
template<class T> inline T rng(T a, T b, T c) { return a > b ? b > c ? a - c : c > a ? c - b : a - b : b > c ? c > a ? b - a : b - c : c - a; }
template<class T> inline T maxi(T a, T b) { return (a == -1 || b == -1) ? -1 : max(a, b); }
template<class T> inline T mini(T a, T b) { return a == -1 ? b : b == -1 ? a : min(a, b); }
template<class T> T maxs(T &a, T b) { if(a < b) return a = b; else return b; }
template<class T> T mins(T &a, T b) { if(a > b) return a = b; else return b; }
template<class T> T maxsi(T &a, T b) { if(a != -1 && (b == -1 || a < b)) return a = b; else return b; }
template<class T> T minsi(T &a, T b) { if(a == -1 || b != -1 && a > b) return a = b; else return b; }

#define ARC(i,a,b) for(Int i=(a);i<(b);++i)
#define ARCH(i,a,b) for(Int i=(a)-1;i>=(b);--i)
#define RC(i,n) ARC(i,0,n)
#define RCH(i,n) ARCH(i,n,0)
#define SRC(i,s) for(Int i=0;(s)[i];++i)
#define ATH(a,b) ((a)>(b)?(a):(b))
#define OTH(a,b) ((a)<(b)?(a):(b))
#define ANTH(a,b) {if((a)<(b))(a)=(b);}
#define ONTH(a,b) {if((a)>(b))(a)=(b);}
#define ACH printf
#define ECH scanf
#define AC putchar
#define EC getchar
#define _ AC('\n');

template<class T> inline T ath(T a, T b) { return a > b ? a : b; }
template<class T> inline T oth(T a, T b) { return a < b ? a : b; }
template<class T> inline T ath(T a, T b, T c) { return a > b ? a > c ? a : c : b > c ? b : c; }
template<class T> inline T oth(T a, T b, T c) { return a < b ? a < c ? a : c : b < c ? b : c; }
template<class T> T anth(T &a, T b) { if(a < b) return a = b; else return b; }
template<class T> T onth(T &a, T b) { if(a > b) return a = b; else return b; }

using ull = unsigned long long;
using Int = long long;

int main() {
	int x, y;
	ECH("%d%d", &x, &y);
	if(x % y) {
		ACH("%d\n", x);
	}
	else {
		ACH("-1\n");
	}
}

Measured memory_bytes: 128