#pragma comment(linker, "/stack:20000000")
#pragma warning(disable:4146)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <complex.h>
#include <fenv.h>
#include <inttypes.h>
#include <stdalign.h>
#include <stdbool.h>
#include <stdint.h>
#include <tgmath.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef pair<string,string> pss;
typedef set<string> sts;
typedef queue<int> qi;
typedef deque<int> di;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef unordered_set<int> usi;
typedef unordered_set<ll> usl;
typedef unordered_map<int,int> umi;
typedef unordered_map<string,int> umsi;
typedef unordered_map<int,string> umis;
#define setbit(n, b) ((n)|((n)>>1<<(b)))
#define removebit(n, b) ((n)&~((n)>>1<<(b)))
#define flipbit(n, b) ((n)^((n)>>1<<(b)))
#define checkbit(n,b) (((n)>>(b))&1)
#define rep(i,n) for (int i=0;i<(n);i++)
#define Rep(i,a,b) for (int i=(a);i<=(b);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define pb(...) push_back(__VA_ARGS__)
#define pf(...) push_front(__VA_ARGS__)
#define sz(a) (int)a.size()
#define X first
#define Y second
#define eprintf(...) __builtin_fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define all(a) (a).begin(),(a).end()
#define reunique(v) v.erase(unique(all(v)),v.end())
#define prl cerr << "called: " << __LINE__ << endl
#define eaq(n,x) __typeof(x) n=x;
#define RET(p,x) return p<<x<<endl,0;
#define Error(p,x) p<<x<<endl;__builtin_abort();
#define Debug(x) cerr<<#x<<" = "<<x<<endl
#define Debug2(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl
#define debug(a,n,m,x) cerr<<"------------------------LET'S DEBUGGING OF "<<#a<<"!--------------------------\n";\
rep(i,n){cerr<<"LINE("<<setw(3)<<i<<") "<<": ";rep(j,m){cerr<<setw(x)<<a[i][j]<<" ";}cerr<<endl;}\
cerr<<"------------------------FINISH DEBUGGING OF "<<#a<<"!--------------------------\n";
const bool multitests=false,alotoftests=false;
const int inf=1e9,ninf=-1e9;const long long infl=1e18,ninfl=-1e18;
const long long h1=239017,h2=731604233;
const long long mod=1000000007,mod2=1000000009;
const int dx[]={1,0,-1,0,1,0,-1,0},dy[]={0,1,0,-1,1,0,-1,0};
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	int x,y;
	cin>>x>>y;
	if (x%y==0)
	{
		RET(cout,-1);
	}
	else
	{
		RET(cout,x);
	}
	return 0;
}

Measured memory_bytes: 256