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