N, K = gets.split.map(&:to_i)
s = gets.chomp

a = []

prec = nil
idx = -1
s.each_char do |c|
    if prec == c
        a[idx] += (c == "R" ? 1 : (-1))
    else
        a.push(c == "R" ? 1 : (-1))
        idx += 1
    end
    prec = c
end

K.times do
    if a.length == 1
        break
    elsif a.length == 2
        aa = a.pop
        a[0] -= aa
        break
    else
        a1 = a.delete_at(-2)
        a2 = a.delete_at(-2)
        a[-1] += (a2 - a1)
    end
end

ans = 0
a.each do |x|
    ans += x.abs() - 1
end

puts ans



