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

score = 0

length = n

n.times do |i|
  next if i == 0
  if s[i-1] == s[i]
    score += 1
    length -= 1
  end
end

if length == 1
  puts score
elsif length >= 2
  if length % 2 == 1
    max = length / 2
    score += [max, k].min * 2
    puts score
  else
    max = length / 2
    if max <= k
      score += (max - 1) * 2 + 1
    else
      score += k * 2
    end
    puts score
  end
end
