from math import sqrt, floor def calc_positive_divisors(num: int) -> list[int]: small_divisors = [] large_divisors = [] for n in range(1, floor(sqrt(num))+1): if num % n == 0: small_divisors.append(n) large_divisors.append(num//n) if small_divisors[-1] == large_divisors[-1]: large_divisors.pop() divisors = small_divisors + list(reversed(large_divisors)) return divisors def main(): A, B = map(int, input().split()) sum_divisors = calc_positive_divisors(A+B) A_rest = A % B B_rest = B % A for divisor in sum_divisors: if not (A_rest + divisor % B) % B and not (B_rest + divisor % A) % A: print(divisor) return print(-1) if __name__ == "__main__": main()