def gcd(x,y): while y>0: x,y = y,x%y return x N,D = map(int,input().split()) d = gcd(N,D) print(N//d-1)