#include #include #include #include #include using namespace std; // using namespace atcoder; typedef long long ll; typedef long double ld; const ll INF = 1LL << 60; const ll MOD = 998244353; // using mint = modint998244353; const string NEW_LINE = "\n"; inline void output_YesNo(bool x) { cout << (x ? "Yes" : "No") << endl; } template inline void chmax(T &lhs, const T &rhs) { lhs = max(lhs, rhs); } template inline void chmin(T &lhs, const T &rhs) { lhs = min(lhs, rhs); } // #include // // void init_output() { cout << fixed << setprecision(15); } int main() { ll p, q; cin >> p >> q; ll pl = p - 1, ql = q - 1, pr = p, qr = q - 1; { ll x = __gcd(pl, ql), y = __gcd(pr, qr); pl /= x, ql /= x, pr /= y, qr /= y; } cout << pl + ql + pr + qr << endl; return 0; }