a, b = map(int, input().split()) i = 1 while True: if (i % a) == (b % i): print(i) break i += 1