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