N,D = map(int,input().split()) def gcd(x,y): return x if y == 0 else gcd(y,x%y) def lcm(x,y): return x * y // gcd(x,y) print(lcm(N,D) // D - 1)