#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
 
    int a,b;
    cin>>a>>b;
    if(a>b) swap(a,b);
    if(gcd(a,b)!=1){
        cout << -1 << endl;
        return 0;
    }
    int l = a*b/gcd(a,b);
    int ans = 0;
    for(int i=1;i<=l;i++){
        if(i%a==0){
            ans++;
            continue;
        }
        for(int j=b;j<=i;j+=b){
            if(i%j==0 || (i-j)%a==0){
                ans++;
                break;
            }
        }
    }
    cout << l-ans << endl;

}