n,k = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
cnt = 1
tar = s[0]
for i in 1..n do
    if tar != s[i-1]
        cnt += 1
        tar = s[i-1]
    end
end

max = n-cnt+2*k
if max >= n
    p n-1
else
    p max
end