io = STDIN
n,k=io.gets.split.map(&:to_i)
str=io.gets.chomp
pat=str.each_char.slice_when{|a,b|a!=b}.map(&:size)
cnt_1over= pat.select{|i|i>1}.size
init_point= pat.select{|i|i>1}.inject(:+)-cnt_1over
if (pat.size-2 >= k)
  puts init_point+k*2
else           #if (pat.size == k)
  puts str.size-1
end
