#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #else #define Debug(...) void(0) #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; int main() { cin.tie(nullptr)->sync_with_stdio(false); int a, b; cin >> a >> b; if (gcd(a, b) != 1) { cout << -1 << '\n'; } else { set s; rep(x, a * b) s.insert(x); for (int i = 0; i <= b; ++i) { for (int j = 0; j <= a; ++j) { s.erase(i * a + j * b); } } cout << s.size() << '\n'; } return 0; }