#YUKI415 def gcd(a,b): while b: a,b=b,a%b return a def lcm(a,b): return a*b//gcd(a,b) n,d=map(int,raw_input().split()) print lcm(n,d)/d-1