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

count = 0
(n - 1).times do |i|
  count += 1 if s[i] == s[i + 1]
end

max = n - 1
left = max - count

if left / 2 <= k
  p max
else
  p count + 2 * k
end
