n, x = gets.chomp.split(" ").map(&:to_i)

if (3 * n / 4.0) <= x && x < n
  puts (3 * x)
elsif (n / 2.0) < x && x < (3.0 * n / 4)
  puts (6 * n) - (6 * x) 
elsif x == (n / 2.0)
  puts (3 * n) / 2
elsif (n / 4.0) < x && x < (n / 2.0)
  puts (6 * x)
else
  puts (3 * n) - (3 * x) + 1
end