#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; int main() { int a, b; cin >> a >> b; if (__gcd(a, b) != 1) { cout << -1 << endl; return 0; } vector ok(a * b + 1, 0); for (int i = 0; i <= b; i++) { for (int j = 0; j <= a; j++) { int n = a * i + b * j; if (n <= a * b) ok[n] = 1; } } int res = 0; for (int i = 0; i <= a * b; i++) if (!ok[i]) res++; cout << res << endl; return 0; }