#include using namespace std; typedef long long ll; typedef pair l_l; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); int A, B; cin >> A >> B; for(int c = 1; c * c <= (A + B); c++) { if(A == c || B == c) continue; if(((A + B) % c) != 0) continue; if(((B + c) % A) != 0) continue; if(((c + A) % B) != 0) continue; cout << c << endl; return 0; } cout << -1 << endl; return 0; }