#include using namespace std; using ll = long long; using p = pair; using P = pair; using V = vector; using VV = vector>; using VVV = vector>>; using VL = vector; using VVL = vector>; using VVVL = vector>>; using Graph = VV; #define rep(i,n) for(int i=0;i<(n);i++) #define all(a) (a).begin(),(a).end() template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int Inf = (1 << 30); ll inf = (1LL << 60); const int MOD = 1e9 + 7; int main() { int a, b; cin >> a >> b; for (int i = 2; i <= max(a, b); i++) { if (a % i == 0 && b % i == 0) { cout << -1 << endl; return 0; } } vector dp(110000, false); dp[0] = true; rep(i, 100000) { if (dp[i]) { dp[i + a] = true; dp[i + b] = true; } } int ans = 0; rep(i, 100000) { if (!dp[i]) ans++; } cout << ans << endl; return 0; }