#include #include #include #include template T gcd(T n, T m) { while (m != 0) { n %= m; std::swap(n, m); } return n; } void solve() { int a, b; std::cin >> a >> b; if (gcd(a, b) > 1) { std::cout << -1 << std::endl; return; } int m = a * b * 2; std::vector ok(m + 1, true); for (int x = 0; a * x <= m; ++x) { for (int y = 0; a * x + b * y <= m; ++y) { ok[a * x + b * y] = false; } } int ans = std::accumulate(ok.begin(), ok.end(), 0); std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }