import math def find_min_c(a, b): s = a + b # Generate all divisors of s divisors = set() for i in range(1, int(math.isqrt(s)) + 1): if s % i == 0: divisors.add(i) divisors.add(s // i) sorted_divisors = sorted(divisors) # Check each divisor in order for c in sorted_divisors: if c == a or c == b: continue # Check if (a + c) is divisible by b and (b + c) is divisible by a if (a + c) % b == 0 and (b + c) % a == 0: return c return -1 a, b = map(int, input().split()) print(find_min_c(a, b))