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 def main(): a, b = map(int, input().split()) l = make_divisors(a + b) ans = float("inf") for c in l: if (b + c) % a == 0 and (a + c) % b == 0: ans = min(ans, c) if ans == float("inf"): print(-1) else: print(ans) if __name__ == '__main__': main()