#include 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)); if((A&1) == (B&1)) ans = -1; cout << ans/2 << endl; }