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

tmp_result = tmp_index = 0
arrf = rl[0...k*2+1]
current = arrf.inject(:+)
pre_first = rl.first
#p arrf

rl.each_cons(k*2+1).with_index do |arr, i|
  unless i.zero?
    current -= pre_first
    current += arr.last
    pre_first = arr.first
  end
  tmp_result, tmp_index = current, i if current > tmp_result
  #p [current, arr]
end

rl[tmp_index..tmp_index+k*2] = [tmp_result]
#p rl
#p"---"

result = rl.map{|e|e-1}.select {|e|e>0}.inject(:+)
p result