#include namespace Math { static uint64_t gcd(uint64_t x, uint64_t y) { while( y != 0 ) { x %= y; std::swap(x, y); } return x; } static uint64_t lcm(uint64_t x, uint64_t y) { return x / gcd(x, y) * y; } }; int main() { uint64_t x, y; scanf("%lu %lu", &x, &y); printf("%lu\n", x / Math::gcd(x, y) - 1); return 0; }