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