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