N, K = gets.split.map(&:to_i)
S = gets.chomp

ans = ff1 = ff2 = bb = 0
("R" + S + "L").chars.each_cons(2).with_index do |(c1, c2), i|
  if c1 == 'R' && c2 == 'L'
    if i == 0 || i == N
      ff1 += 1
    else
      ff2 += 1
    end
  elsif c1 =='L' && c2 == 'R'
    bb += 1
  elsif i > 0 && i < N
    ans += 1
  end
end

k = [K, bb].min

kk = [k, ff2].min
ans += kk * 2
k -= kk

kk = [k, ff1].min
ans += kk
k -= kk

puts ans
