import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}
import java.lang.{Character => char}

object Main extends App {
  val Array(n,k) = in.readLine.split(" ").map(_.toInt)
  val s = in.readLine.map(char.getNumericValue)

  val table = mu.ArrayBuffer.empty[Int]
  s./:(-1)( (b, i) => {
    val v = if(i == 1) 1 else -1
    if(i != b) table.append(v)
    else table(table.size-1) += v
    i
  })

  val sums = table.scanLeft(0)((acc,i) => acc + i.abs)
  0 +=: table

  def rec(acc:Int, cnt:Int, left:Int, right:Int, now:Int):Int = {
    if(right == table.size) acc
    else {
      val leftCnt = if(table(left) < 0) 1 else 0
      if(cnt-leftCnt == k && now == 1)
        rec(acc max (sums(right)-sums(left)), cnt-leftCnt, left+1, right, now)
      else
        rec(acc max (sums(right)-sums(left)), cnt+(now^1), left, right+1, now^1)
    }
  }

  val ans = rec(0,0,0,1,s.head)
  println(ans)
}