import math n,d = map(int,input().split()) g = math.gcd(n,d) print(n//g-1)