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)
break_cnt=pat.size-1
init_point= pat.select{|i|i>1}.map{|i|i-1}.inject(:+)||0
if n==1
  puts 0
elsif (break_cnt/2<k)
  puts str.size-1
else
  puts init_point+k*2
end
