import fractions n, d = map(int,input().split()) if n == d: print(0) exit() if fractions.gcd(n, d) == 1: ans = n - 1 else: if n % d == 0: ans = n // d - 1 else: ans = n // d print(ans)