A, B = map(int, input().split()) def do(): for x in range(100000): if x % A == B % x: return x print(do())