N, X = map(int ,input().split())

if X==N/2:
    print(3*X)
else :
    if X>N/2:
        X = N-X
    L = X + (N-X) + X 
    rest_ab = N-2*X
    while rest_ab > X:
        L += 2*X
        # print('>X',L)
        rest_ab -= X
    if rest_ab == X:
        L += 2*X
    elif rest_ab < X:
        # print('rest_ab=', rest_ab)
        L += X + 2*(X-1) + 1
    print(L)

