#define _GLIBCXX_DEBUG #include using namespace std; int main(){ int A,B; cin>>A>>B; int ans=-1; vector divisors(0); vector divisors_rev(0); for(int C=1;C*C<=A+B;C++){ if((A+B)%C==0){ divisors.push_back(C); divisors_rev.push_back((A+B)/C); } } reverse(divisors_rev.begin(),divisors_rev.end()); for(int d:divisors_rev){ divisors.push_back(d); } for(int d:divisors){ if((A+d)%B==0&&(B+d)%A==0){ ans=d; break; } } cout<