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