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

first = 1
while first < n && k > 0
    if s[first - 1] != s[first] then
        last = first
        while last < n - 1
            if s[last] == s[first] && s[last + 1] == s[first - 1] then
                break
            end
            last += 1
        end
        for i in first.upto(last)
            if s[i] == 'L' then
                s[i] = 'R'
            else
                s[i] = 'L'
            end
        end
        k -= 1
    end
    first += 1
end

count = 0
for i in 1.upto(n - 1)
    if s[i - 1] != s[i] then
        count += 1
    end
end

puts n - 1 - count
