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