A, B = map(int, input().split()) x = 1 while not (x % A == B % x): x += 1 print(x)