a, b = map(int,input().split()) for i in range(1, 100001): if i % a == b % i: print(i) exit(0)