#pragma GCC optimize("Ofast") #include using namespace std; #define INF (1e9) #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) x.begin(),x.end() const long double PI = acos(-1.0L); const long long MOD = 1000000007LL; //const long long MOD = 998244353LL; typedef long long ll; typedef pair pii; typedef pair pll; template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; } /////////////////////////////////////////////////////////////////////////////////////////////////// int gcd(int x, int y) { return x ? gcd(y%x,x) : y; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int A,B; cin >> A >> B; if (gcd(A,B) != 1) { cout << -1 << endl; return 0; } int cnt = 0; for (int i = 1; i <= A*B; ++i) { bool ok = false; rep(j,B) { if (i - A*j >= 0 && (i - A*j)%B==0) ok = true; } if (!ok) cnt++; } cout << cnt << endl; }