#include using namespace std; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int a, b; cin >> a >> b; int ab = a + b; vector F(ab + 1, true); for(int i = 1; i <= (int)(sqrt(ab)); i++){ if(F[i]){ bool x = (a + b) % i == 0; bool y = (b + i) % a == 0; bool z = (i + a) % b == 0; if(x and y and z){ cout << i << endl; return 0; } if(i == 1) continue; for(int j = i + i; j <= ab; j += i){ F[j] = false; } } } cout << -1 << endl; return 0; }