N,D = map(int,input().split()) from math import gcd print(N//(gcd(N,D)) - 1)