n, x = map(int,input().split())

if n == 2:
    ans = 3

elif n % 2 == 1:
    ans = (n-1) * 3

else:
    if x > n//2:
        x = n - x

    std = (n//2) * 3
    ans = std + (n//2 - x) * 3

print(ans)