#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair P; int main(){ ll a, b; cin >> a >> b; for (ll i = 1; i * i <= a + b; i++) { if (a == i || b == i) continue; if ( (a + b) % i != 0) continue; if ((i + b) % a == 0 && (i + a) % b == 0) { cout << i << endl; return 0; } ll j = (a + b) / i; if ((j + b) % a == 0 && (j + a) % b == 0) { cout << j << endl; return 0; } } cout << -1 << endl; return 0; }