from collections import defaultdict def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] a, b = map(int, input().split()) m = make_divisors(a+b) for c in m: if (a+b)%c == 0 and (b+c)%a == 0 and (c+a)%b == 0: print(c) exit() print(-1)