A,B = map(int,input().split()) if A < B or A > 300 or B <= 0: raise ValueError i = 0 while True: i += 1 if i % A == B % i: print(i) break