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