n,k = gets.chomp.split(" ").map{|i|i=i.to_i}
s = gets.chomp

now_muki = s[0]
count=0
saisho=0
(n-1).times{|i|
  if s[(i+1)]!=now_muki then
    count+=1
    now_muki=s[(i+1)]
  else
    saisho+=1
  end
}
#puts "saisho : #{saisho}\ncount : #{count}"
if count%2==0 then
  puts saisho + ([k,(count/2)].min*2)
elsif count%2==1 then
  if k < ((count/2)+1) then
    puts saisho + (2*k)
  else
    puts s.length-1
  end
end



