#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e15 + 7;

ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
/*---------------------------------------------------------------------------------------------------------------------*/

const int M = 2e5 + 5;



ll val[13];

bool calc(ll sum , ll mask){
    for(int i = 1 ; i <= 9 ; i++){
        if((1LL<<i)&mask){
            if(sum%i) return false;
        }
    }
    return true;
}


map<vector<int> , ll> has , dp;

ll get_dp(int fir , int len_left , vector<int> vec , int mask){
    if(len_left == 0){
        for(int i = 1 ; i <= 9 ; i++){
            if((1<<i)&mask){
                if(vec[i]) return 0;
            }
        }
        return 1;
    }
    vector<int> vv;
    vv.push_back(len_left);
    for(int i = 0 ; i <= 9 ; i++)  vv.push_back(vec[i]);

    if(has.count(vv)) return dp[vv];

    has[vv] = 1;

    ll forbidden = 0;
    int st = (fir == 0 ? 0 : 1);

    for(int put = st ; put <= 9 ; put++){

        vector<int> previ = vec;
        for(int i = 1 ; i <= 9 ; i++){
            vec[i] = (vec[i]*10 + val[put])%i;
        }

        forbidden += get_dp(0 , len_left - 1 , vec , mask|(1<<put));

        vec = previ;
    }
    dp[vv] = forbidden;
    return forbidden;
}

ll get(ll num){

    if(num < 11) return num;
    string str = to_string(num);
    int n = str.length();
    ll ans = 0;

    vector<int> vec(10 , 0);

    for(int tot_len = 1 ; tot_len < n ; tot_len++){
        ans += get_dp(1 , tot_len , vec , 0);
    }

   // cout<<"fir "<<ans<<endl;

    for(int i = 0 ; i <= 9 ; i++) vec[i] = 0;
    ll d_sum = 0;
    int mask = 0;

    for(int i = 0 ; i < n ; i++){
        int el = str[i] - '0';
        for(int put = 0 ; put <= 9 ; put++){
            if(put + i == 0) continue;
            if(put >= el) break;
            vector<int> temp = vec;
            for(int j = 1 ; j <= 9 ; j++)  temp[j] = (vec[j]*10 + val[put])%j;
            //cout<<i<<" pr "<<put<<"  "<<ans<<endl;
            ans += get_dp(0 , n - 1 - i , temp , mask|(1<<put));
            //cout<<i<<" af "<<put<<"  "<<ans<<endl;
        }

        for(int j = 1 ; j <= 9 ; j++){
            vec[j] = (vec[j]*10 + val[el])%j;
        }
        mask |= (1<<el);
    }
   // cout<<"sec "<<ans<<endl;
    //cout<<"till "<<ans<<endl;
    d_sum = 0;
    mask = 0;

    for(int i = 0 ; i < n ; i++){
        int el = str[i] - '0';
        d_sum += val[el];
        mask |= (1<<el);
    }

    int add = 1;

    for(int i = 1 ; i <= 9 ; i++){
        if((1<<i)&mask){
            if(d_sum%i) add = 0;
        }
    }
    ans += add;
    //ans += 9;
    return ans;

}

int main(){

    ll x, y;
    cin >> x >> y;
    
    if(x%y == 0){
       cout << -1;
    }
    else{
       y++;     
       cout << x*y;
    }


}


Measured memory_bytes: 256