#include using namespace std; using ll = long long; constexpr char newl = '\n'; // a * x + b * y == gcd(a, b) なるx, yを計算 // 返り値はgcd(a, b) template T extgcd(T a, T b, T& x, T& y) { T d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int a, b; cin >> a >> b; if (__gcd(a, b) != 1) { cout << -1 << newl; return 0; } vector dp(100001, false); dp[0] = true; for (int i = 0; i <= 100000; i++) { if (!dp[i]) continue; if (i + a <= 100000) dp[i + a] = true; if (i + b <= 100000) dp[i + b] = true; } int ans = 0; for (int i = 1; i <= 100000; i++) { ans += !dp[i]; } cout << ans << newl; return 0; }