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