n, k = gets.split(' ').map(&:to_i)
s = gets.chomp
a = []
n.times do |i|
  a << i if (s[i-1] != s[i])
end
# p a
diff = (a.length-1).times.map do |i|
  a[i+1] - a[i] - 1
end
# p diff

a[-1] = n-1
# p a

max = a.length - 2*k > 0 ? 0 : s.length - 1
(a.length - 2*k).times do |i|
  start = a[i]
  last = a[i + 2 * k]
  # p "#{start}:#{last}"
  tmp_max = last - start
  tmp_max += diff[0..(i-1)].inject(:+) if i > 0
  tmp_max += diff[(i+2*k)..-1].inject(:+) if i < a.length - 2*k - 1
  max = tmp_max if max < tmp_max
end
p max
