#include<bits/stdc++.h>

using namespace std;

#define int long long

int gcd(int a, int b) {
    while (a > 0 && b > 0) {
        int c = a % b;
        a = b, b = c;
    }
    return a + b;
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x;
    cin >> n >> x;
    if (2 * x < n) {
        cout << n + 2 * x + lcm(x, n - 2 * x) + 1 << '\n';
    }
    else if (2 * x == n) {
        cout << n + x << '\n';
    }
    else {
        cout << n + lcm(n - x, x) + 1 << '\n';
    }
    return 0;
}

