first = input() split_first = first.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