def gcd(a, b): while b != 0: a, b = b, a % b return(a) N, D = map(int, input().split()) print(N//gcd(N, D) - 1)