#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 = -1; for(int x = 1; x * x <= a + b; x++){ if(x == a || x == b){ continue; } if((a + b) % x != 0){ continue; } if((a + x) % b != 0){ continue; } if((b + x) % a != 0){ continue; } ans = x; break; } int x = a + b; if(ans == -1 && (a + b) % x == 0 && (a + x) % b == 0 && (b + x) % a == 0){ ans = x; } cout << ans << endl; return 0; }