def min(a,b) a<b ? a:b end
N,K=gets.split.map(&:to_i)
S=gets.chomp.split("")

lr = 0
rl = 0
point = 0
(N-1).times do |i|
  if S[i] == S[i+1]
    point += 1
  else
    if S[i] == "L"
      lr += 1
    else
      rl += 1
    end
  end
end

point += min(K, min(lr,lr)) * 2
p point