n, d =[ int(v) for v in input().split() ] def gcd(a,b): if a < b: a, b = b, a while b >= 1: a, b = b, a % b return a print(n//gcd(n,d)-1)