first = input() first_split = data.split() A = int(split_first[0]) B = int(split_first[1]) x = 1 while(true): if(x % A == B % x): print(x) break x+=1