from math import gcd from sys import stdin, stdout input = lambda: stdin.readline().rstrip() write = stdout.write lcm = lambda x, y: x * y // gcd(x, y) def main(): N, D = map(int, input().split()) ans = lcm(N, D) // D - 1 print(ans) main()