A, B = map(int, input().split()) D = [] for C in range(1, int((A + B) ** 0.5) + 100): if (A + B) % C == 0: D.append(C) D.append((A + B) // C) for C in sorted(D): if A != C and B != C and (A + B) % C == (B + C) % A == (C + A) % B == 0: print(C) break else: print(-1)