#include #include #include #include #include #include #include using namespace std; using ll = long long; int gcd(int n, int m) { if (n < m) swap(n, m); while (m != 0) { int r = n % m; n = m; m = r; } return n; } int main() { int a, b; cin >> a >> b; int c = gcd(a, b); if (c > 1) { cout << -1 << endl; exit(0); } if (a == 1 || b == 1) { cout << 0 << endl; exit(0); } int r = 0; for (int i = 1; i < a * b; i++) { int f = 1; for (int j = 0; j <= i; j += a) { int t = i - j; if (t % b == 0) { f = 0; break; } } r += f; } cout << r << endl; return 0; }