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