#include using namespace std; int main() { int A, B; int i; cin >> A >> B; for (i=max(A, B); i > 0; i--) { if (A % i == 0 && B % i == 0) { A /= i; B /= i; break; } } //cout << A << " " << B << " " << i << endl; if (min(A, B) == max(A, B) - 1) { cout << (min(A, B) + 2) * i << endl; } else if (min(A, B) == max(A, B) - 2) { cout << (min(A, B) + 1) * i << endl; } else { cout << -1 << endl; } return 0; }