#include #define rep(i, n) for(int i=0;i<(n);++i) #define per(i, n) for(int i=(n)-1;i>=0;--i) #define repa(i, n) for(int i=1;i<(n);++i) #define foreach(i, n) for(auto &i:(n)) #define pii pair #define pll pair #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) using ll = long long; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; using namespace std; template using vvector = vector>; template using vvvector = vector>>; template using priority_queuer = priority_queue, greater>; template bool chmax(t &a, u b){if(a bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define OUTPUT(x) (output(x), output("\n")) #else #define OUTPUT(x) (void)0 #endif ll modpow(ll x, ll b){ ll res = 1; while(b){ if(b&1)res = res * x % MOD; x = x * x % MOD; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll gcd(ll a, ll b){ while(b){ a %= b; swap(a, b); } return a; } ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } int main(){ ll a; ll b; cin >> a >> b; ll lc = lcm(a, b); if(gcd(a, b)!=1){ cout << -1 << endl; return 0; } cout << (lc - lc / a - lc / b + 1) / 2 << endl; return 0; }