main = do [n,d] <- map read . words <$> getLine print (pyon n d) pyon n d = q * (div d (gcd d m)) - if m==0 then 1 else 0 where (q,m) = divMod n d