A, B = map(int, input().split()) X = 0 L = [] for x in range(1,A*B): if x % A == B % x: L.append(x) answer = min(L) print(answer)