from sys import stdin def primeFactors(n): factors = [] apnd = factors.append while n >= 4: if n % 2: break else: n //= 2 apnd(2) i = 3 while n >= i * i: if n % i: i += 2 else: n //= i apnd(i) apnd(n) return factors def main(): A, B = map(int, input().split()) if A == B: print(-1) return x = primeFactors(A + B) if len(x) == 1: print(-1) else: print(x[0]) input = lambda: stdin.readline().rstrip() main()