n, k = gets.split.map{|x|x.to_i}
s = gets.chomp.each_char.map {|x| x == '0' ? 0 : 1}

# stand, reverse, stand...
stands = []
reverses = []

tmp = 0
i = 0

tmp = 0
while i < n && s[i] == 1
  tmp += 1
  i += 1
end
reverses << tmp

while i < n
  tmp = 0
  while i < n && s[i] == 0
    tmp += 1
    i += 1
  end
  stands << tmp

  tmp = 0
  while i < n && s[i] == 1
    tmp += 1
    i += 1
  end
  reverses << tmp
end

removed_people = 0
hole_count = stands.size

while hole_count > k && !stands.empty?
#  p stands
#  p reverses
#  puts "---"


  hole_count -= 1

  if stands[0] + reverses[0] + reverses[1] < stands[-1] + reverses[-1] + reverses[-2]
    removed_people += stands.shift + reverses.shift
  else
    removed_people += stands.pop + reverses.pop
  end
end
#p stands
#p reverses


puts(stands.reduce(0, :+) + reverses.reduce(0, :+))
