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

L = [N, N - X, X, N - X]
i = 0
S = 0
while True:
    ip = (i + 3) % 4
    S += L[ip]
    L[i] -= L[ip]
    if L[i] == 0:
        break
    i = (i + 1) % 4

print(sum(L) - 1 + S)
