



a = gets.chomp.split(" ").map(&:to_i)
stub = 0
if a[0] / 2.0 > a[1]
stub = a[1]
else
stub = a[0] - a[1]# - 1
end

#if a[0] % 2 == 0
  stub = 1 if a[0] % stub != 0 && stub < a[0] / 2.0
p a[0]* 3 - stub * 3
#else
#p a[0]* 3 - 3
#end

