#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; using vi = vector; using vii = vector; using vl = vector; using vll = vector; #define INF 10e17 #define rep(i,n) for(long long i=0; i()) #define debug(x) std::cerr << (x) << std::endl; #define roll(x) for (auto&& itr : x) { debug(itr); } template inline void chmax(T &ans, T t) { if (t > ans) ans = t;} template inline void chmin(T &ans, T t) { if (t < ans) ans = t;} // 最大公約数を求める(ユークリッドの互除法). long long gcd (long long x, long long y) { if (y > x) swap(x,y); if (y == 0) return x; return gcd(x%y,y); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll a,b; cin >> a >> b; auto Max = a * b; map ok; if (gcd(a,b) != 1) { cout << -1 << endl; return 0; } for (int x = 0; x < Max; ++x) { for (int y = 0; y < Max; ++y) { if ((x*a) + (y*b) > Max) break; ok[(x*a) + (y*b)] = true; } } int ans = 0; for (int i = 0; i <= Max; ++i) { if (!ok[i]) ans += 1; } cout << ans << endl; }