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