n, k = gets.split.map(&:to_i)
s = gets.chomp

ans = 0
c_l2r = 0
c_r2l = 0
n.times do |i|
    if s[i] == "R"
        next if i == n - 1
        ans += 1 if s[i+1] == "R"
    else
        next if i == 0
        ans += 1 if s[i-1] == "L"
    end
    next if i == 0
    if s[i] != s[i-1]
        if s[i] == "R"
            c_l2r += 1 
        else 
            c_r2l += 1 
        end
    end
end

if c_l2r > c_r2l
    c_l2r, c_r2l = c_r2l, c_l2r
end

ans += 2*[k, c_l2r].min
k -= c_l2r
if k > 0 and c_r2l > c_l2r
    ans += 1
end

puts ans