A, B = map(int, input().split()) def solve(): for x in range(1, 100000): if x % A == B % x: return x print(solve())