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