n,k=gets.split.map(&:to_i)
s=gets.split("")
result=0

(n-1).times do |i|
  if s[i]==s[i+1]
    result += 1
  end
end
cut = n - 1 - result
(cut-2).times do |j|
  result += 2
  k -= 1
  break if k==0
end
if k>=2
  result +=2
elsif k==1
  result += 1
end
puts result