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

count = 1
pre = s[0]
s.each_char do |c|
    next if c == pre
    count += 1
    pre = c
end

if count <= 2*k then
    ans = n - 1
else
    ans = n + 2*k - count
end

puts ans