a, b = map(int, input().split()) for x in range(a + b + 1): if x % a == b % x: print(x) break