#約数全部 def Divisors(N): N=abs(N) L,U=[],[] k=1 while k*k <=N: if N%k== 0: L.append(k) if k!=N//k: U.append(N//k) k+=1 return L+U[::-1] #================================================ A,B=map(int,input().split()) D=Divisors(A+B) C=-1 for c in D[::-1]: if (A+c)%B==(B+c)%A==0: C=c print(C)