#include #include using namespace std; const int inf = 1012345678; int main() { int A, B; cin >> A >> B; int ans = 0; for (int i = 1; i <= 2 * A * B; ++i) { bool ok = false; for (int j = 0; j <= 2 * B; ++j) { for (int k = 0; k <= 2 * A; ++k) { if (j * A + k * B == i) { ok = true; } } } if (!ok && i <= A * B) ++ans; if (!ok && i > A * B) ans = inf; } if (ans >= inf) cout << -1 << endl; else cout << ans << endl; return 0; }