#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) continue; if (b == i) continue; if ((a + b) % i == 0) { if ((i + b) % a == 0 && (i + a) % b == 0) { cout << i << endl; return 0; } } } cout << -1 << endl; return 0; }