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