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