def gcd(a, b): while b: a, b = b, a%b return a N, D = map(int, input().split()) ans = N // gcd(N, D) - 1 print(ans)