a,b=gets.split.map &:to_i d=a.gcd b k=(d*(1.0/a+1.0/b)).to_i+1 c=a*(b/d*k-1)-b p a!=c&&b!=c&&(a+b)%c==0 ? c : -1