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