#include using namespace std; #define rep(i, n) for(int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for(int i = a; i < (int)b; ++i) #define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i) typedef long long ll; typedef long double ld; const int Inf = 1e9; const double EPS = 1e-9; const int MOD = 1e9 + 7; bool check(ll x, ll y, ll z) { if ((x + y) % z != 0) return false; if ((x + z) % y != 0) return false; if ((y + z) % x != 0) return false; return true; } int main() { cin.tie(nullptr); ios::sync_with_stdio(0); ll a, b; cin >> a >> b; ll c = a + b; for (ll i = 1; i * i <= c; ++i) { if (c % i != 0) continue; if (i == a || i == b) continue; if (check(a, b, i)) { cout << i << endl; return 0; } } cout << -1 << endl; return 0; }