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