#include using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll A, B; cin >> A >> B; ll m = sqrt(A + B); ll t = A + B; for (ll k = 1; k <= m; k++) { if (t % k == 0) { ll C1 = k; ll C2 = (A + B) / k; if ((B + C1) % A == 0 && (A + C1) % B == 0) { cout << C1 << "\n"; return 0; } if ((B + C2) % A == 0 && (A + C2) % B == 0) { cout << C2 << "\n"; return 0; } } } cout << "-1\n"; return 0; }