#include using namespace std; using ll = long long; #define fi first #define se second vector finddivisor(int x){ vector divisor; for(int i=1; i*i<=x ;i++) { if(x%i==0){ divisor.push_back(i); } } return divisor; }//整数xの約数が入ったvectorを返すよ int main(){ ll a,b; cin >> a >> b; vector v=finddivisor(a+b); for(int i=0;i < v.size();i++) { if((b+v.at(i))%a == (v.at(i)+a)%b && (b+v.at(i))%a==0 && v.at(i)!=a && b!=v.at(i)){ cout << v.at(i) << endl; return 0; } } cout << -1 << endl; }