#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int gcd(int n,int m){return m?gcd(m,n%m):n;}
int lcm(int n,int m){return n*m/gcd(n,m);} 
int main(){
    int A,B;
    cin >> A >> B;
    int ans = lcm(A, B);
    ans -= (ans/A + ans/B) - (ans/(A*B));
    ans /= 2;
    if((A&1) == (B&1)) ans = -1;
    
    cout << ans << endl;
}