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

rl = []
count = 0
c = s.first
s.each do |cc|
  if c==cc
    count+=1
  else
    rl << count
    count=1
    c=cc
  end
end
rl << count

if rl.length < k*2+1
  p rl.inject(:+)-1
  exit
end

p rl.map {|e|e-1}.inject(:+) + k*2

