#include <bits/stdc++.h>

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int gcd(int,int);

int main(){
    int x,y;
    int ans = 0;
    cin >> x >> y;
    int g = gcd(x,y);
    x /= g;
    y /= g;

    REP(i,g) ans += ((x-1)+(y - 1));
    ans += (g + 1);
    cout << ans << endl;
    return 0;
}

int gcd(int a, int b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    else gcd(b,(a % b));
}
