A,B=[int(x) for x in input().split()] for x in range(1,10**5+1): if x%A==B%x: print(x) break