# A+B=n*C # B+C=m*A # C+A=l*B # 2 * (A+B+C) = n*C + m*A + l*B def divisor(n): n2 = int((n**0.5)+1) + 1 ret = set() for i in range(1,n2): if n%i==0: ret.add(i) ret.add(n//i) ret = list(ret) ret.sort() return ret def solve(): A,B=map(int,input().split()) Cs=divisor(A+B) #print(Cs) for c in Cs: if (B+c)%A==0 and (c+A)%B==0 and A!=c and B!=c: return c return -1 print(solve())