n,k = gets.split.map(&:to_i)
s = gets.chomp
ans = 0
cnt = 0
cnt += 1 if s[0] == "L"
cnt += 1 if s[n-1] == "R"
cnt -= 1 if s[0] == "L" || s[n-1] == "R"
1.upto(n-1) do |i|
  if s[i-1] == s[i]
    ans += 1
  elsif s[i-1] == "R" && s[i] == "L"
    cnt += 1
  else
    cnt
  end
end

if cnt <= k
  p n-1
else
  p ans + k * 2
end