#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

int main() {
    int64_t n, x;
    cin >> n >> x;

    int64_t top = x, bottom = n, side = n - x;
    int32_t pos = 0;

    int64_t len = 0;
    while (side > 0 && bottom > 0) {
        if (pos == 0) {
            len += top;
            ++pos;
        } else if (pos == 1) {
            len += side;
            bottom = top;
            ++pos;
        } else if (pos == 2) {
            if (side < bottom) {
                len += side;
                top -= side;
                bottom -= side;
                pos = 1;
            } else {
                len += bottom;
                pos = 3;
                side -= bottom;
            }
        } else if (pos == 3) {
            len += bottom;
            pos = 2;
        }
    }

    cout << len << endl;

    return 0;
}