#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int64_t A, B; cin >> A >> B; vector C; for (int64_t i = 1; i * i < A + B + 1; i++) { if ((A + B) % i == 0) { C.emplace_back(i); C.emplace_back((A + B) / i); } } int64_t res = INT64_C(1) << 50; for (const auto &c : C) { if (A != c && B != c && (A + B) % c == 0 && (A + c) % B == 0 && (B + c) % A == 0) res = min(res, c); } if (res != INT64_C(1) << 50) { cout << res << '\n'; } else { cout << -1 << '\n'; } return 0; }