from math import gcd def lcm(a, b): return a * b // gcd(a, b) n, d = map(int, input().split()) l = lcm(n, d) print(l // d - 1)