lines = $stdin.read
array = lines.split("\n")

N = array[0].split(" ")[0].to_i
X = array[0].split(" ")[1].to_i
l = 0

if X <= N - X
  l += X
  l += N - X
  l += 2 * X
  l += 3 * (N-2*X)
else
  l += X
  l += 4 * (N-X)
end

puts l
