n,k = gets.chomp.split.collect{ |item| item.to_i}
s = gets.chomp
s.insert(0,"R")
s += "L"
 
ans = n
badn = 0
1.upto(n) do |ni|
  if(s[i] == "R")
  	badn += 1 if (s[i] != s[i+1])
  else
    badn += 1 if (s[i] != s[i-1])
  end
end
ans -= [1,(badn - 2*k)].max
 
puts ans