N, X = map(int, raw_input().strip().split())

path = 0
if X < N/2.0:
    res = N - X
    path += N

    while res > X:
        path += X*2
        res -= X

    if res != 0:
        path += (X*2 - 1)

else:
    res = X
    path += N

    while res > N-X:
        path += (N-X)*2
        res -= (N-X)

    if res != 0:
        path += ((N-X)*2 - 1)

print path
