#include using namespace std; int main() { int a, b; cin >> a >> b; if (gcd(a, b) != 1) { cout << -1 << endl; return 0; } vector good(a * b); for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { if (b * i + a * j >= a * b) continue; good.at(b * i + a * j) = true; } } int ans = 0; for (int i = 0; i < a * b; i++) ans += !good.at(i); cout << ans << endl; }