#include #define rep(i,n) for(int i=0;i ; const ll INF = 1e18; const int MOD = 1000000007; int main(){ ll a,b; cin >> a >> b; ll ans = INF; for(ll c = 1;c * c <= a+b;c++){ if((a+b)%c == 0){ if((b+c)%a == 0 && (c+a)%b == 0 && a != c && b != c) ans = min(ans,c); if((b+(a+b)/c)%a == 0 && ((a+b)/c+a)%b == 0 && a != (a+b)/c && b != (a+b)/c) ans = min(ans,(a+b)/c); } } cout << (ans==INF ? -1 : ans)<< endl; return 0; }