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

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

if s.length-1 < 2*k
  p s.length-1
  exit
end

#p rl

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