local n,k=io.read("n","n","l")
local s=io.read()
local counter=0
for i=1,n-1 do
    if s:byte(i)~=s:byte(i+1) then
        counter=counter+1
    end
end
print(n-1-(counter-2*k>0 and counter-2*k or 0))