input = gets.chomp.split(" ").map(&:to_i)
N = input[0]
K = input[1]

people = gets.chomp.split("")

happieness = -1

befo = people[0]
turning_points = []

people.each_with_index do |e,i|
  if e == befo
    happieness += 1
  elsif turning_points.empty? || i != turning_points.last+1
    turning_points << i
  end
  befo = e
end

if !turning_points.empty?
	turning_points.pop
end

if turning_points.length >= K
  happieness += 2*K
else
  happieness = people.length - 1
end

puts happieness