#include using namespace std; int main() { long long a, b; cin >> a >> b; long long d = a + b; for (long long c = 2; c * c <= d; c++) { if (d % c == 0) { if ((a + c) % b == 0 && (b + c) % a == 0) { cout << c << endl; return 0; } } } cout << -1 << endl; return 0; }