from math import lcm n, d = map(int, input().split()) ans = lcm(n, d) // d - 1 print(ans)