#include using namespace std; typedef long long ll; #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) { cerr << (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() { int a,b; cin >> a >> b; if (gcd(a,b) != 1) { cout << -1 << endl; return 0; } int const mmax = a * b; int ans = 0; map mp; for (int x = 0; x * a <= mmax; ++x) { for (int y = 0; x * a + y * b <= mmax; ++y) { mp[x * a + y * b] = true; } } for (int i = 0; i <= mmax; ++i) { if (!mp[i]) ans += 1; } cout << ans << endl; }