def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors a,b = map(int,input().split()) cli = make_divisors(a+b) for i in range(len(cli)): c = cli[i] if a == c or b == c: continue if (a+b) % c == 0 and (b+c) % a == 0 and (c+a) % b == 0: print(c) exit() print(-1)