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