#include using namespace std; int main(){ int a,b;cin >> a >> b; vector v; int num=a+b; for(int i=1;i*i<=num;i++){ if(num%i==0){ v.push_back(i); if(i*i!=num){ v.push_back(num/i); } } } sort(v.begin(),v.end()); for(int i=0;i=b&&b+v[i]>=a&&a!=v[i]&&b!=v[i]){ if((a+v[i])%b==0&&(b+v[i])%a==0){ cout << v[i] << endl; return 0; } } } cout << -1 << endl; }