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