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