#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; template V divisor(Z n) { V res; Z i; for (i = 1; i * i < n; ++i) if (n % i == 0) res.push_back(i), res.push_back(n / i); if (i * i == n) res.push_back(i); sort(begin(res), end(res)); return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int a, b; cin >> a >> b; for (int c : divisor(a + b)) { if ((a + c) % b == 0 and (b + c) % a == 0) { return cout << c << '\n', 0; } } cout << -1 << '\n'; }