#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define int long long int #define rep(i, n) for(int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) using namespace std; typedef pair P; const int INF = 1e15; const int MOD = 1e9+7; template using vector2 = vector>; template vector2 initVec2(size_t n0, size_t n1, T e = T()){ return vector2(n0, vector(n1, e)); } template using vector3 = vector>>; template vector3 initVec3(size_t n0, size_t n1, size_t n2, T e = T()){ return vector3(n0, vector2(n1, vector(n2, e))); } signed main(){ ios::sync_with_stdio(false); cin.tie(0); int a, b; cin >> a >> b; int ans = INF; for(int x = 1; x * x <= a + b; x++){ if((a + b) % x != 0){ continue; } int y = (a + b) / x; if(x != a && x != b && (a + x) % b == 0 && (b + x) % a == 0){ ans = min(ans, x); } if(y != a && y != b && (a + y) % b == 0 && (b + y) % a == 0){ ans = min(ans, y); } } cout << (ans == INF ? -1 : ans) << endl; return 0; }