import math steps,width = (int(n) for n in input().split(' ')) if steps == width: print(0) else: print(steps // math.gcd(steps,width) - 1)