#include #include #include using namespace std; int main(){ int A, B; cin >> A >> B; vector f; for (int i = 1; i * i <= A + B; i++){ if ((A + B) % i == 0){ f.push_back(i); f.push_back((A + B) / i); } } sort(f.begin(), f.end()); for (int C : f){ if ((B + C) % A == 0 && (C + A) % B == 0){ cout << C << endl; return 0; } } cout << -1 << endl; }