N, K = list(map(int, input().split()))

S = "1" + eval(input()) + "1"

arr = []

cnt = 0

flg = 1

for s in S:

    if s == "1" and 1 - flg:

        flg = 1

        arr.append(cnt)

        cnt = 1

    elif s == "0" and flg:

        flg = 0

        arr.append(cnt)

        cnt = 1

    else:

        cnt += 1

arr.append(cnt)

csum = [0] * (len(arr)+1)

for i in range(len(arr)):

    csum[i + 1] = csum[i] + arr[i]

ans = 0

tmp = 0

for i in range(0, len(csum), 2):

    l = i

    r = min(i + 2*K + 1, len(csum) - 1)

    tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)

    ans = max(ans, tmp)

if len(csum) == 2:

    print((csum[1] - 2))

else:

    print(ans)

from itertools import accumulate

N, K = list(map(int, input().split()))

S = "1" + eval(input()) + "1"

arr = []

cnt = 0

flg = 1

for s in S:

    if s == "1" and 1 - flg:

        flg = 1

        arr.append(cnt)

        cnt = 1

    elif s == "0" and flg:

        flg = 0

        arr.append(cnt)

        cnt = 1

    else:

        cnt += 1

arr.append(cnt)

csum = [0] + list(accumulate(arr))

ans = 0

tmp = 0

for i in range(0, len(csum), 2):

    l = i

    r = min(i + 2*K + 1, len(csum) - 1)

    tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)

    ans = max(ans, tmp)

if len(csum) == 2:

    print((csum[1] - 2))

else:

    print(ans)

N, K = list(map(int, input().split()))
S = "1" + eval(input()) + "1"
arr = []
cnt = 0
flg = 1
for s in S:
    if s == "1" and 1 - flg:
        flg = 1
        arr.append(cnt)
        cnt = 1
    elif s == "0" and flg:
        flg = 0
        arr.append(cnt)
        cnt = 1
    else:
        cnt += 1
arr.append(cnt)
csum = [0] * (len(arr) + 1)
for i in range(len(arr)):
    csum[i + 1] = csum[i] + arr[i]
ans = 0
tmp = 0
for i in range(0, len(csum), 2):
    l = i
    r = min(i + 2 * K + 1, len(csum) - 1)
    tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)
    ans = max(ans, tmp)
if len(csum) == 2:
    print((csum[1] - 2))
else:
    print(ans)

from itertools import accumulate

N, K = list(map(int, input().split()))
S = "1" + eval(input()) + "1"
arr = []
cnt = 0
flg = 1
for s in S:
    if s == "1" and 1 - flg:
        flg = 1
        arr.append(cnt)
        cnt = 1
    elif s == "0" and flg:
        flg = 0
        arr.append(cnt)
        cnt = 1
    else:
        cnt += 1
arr.append(cnt)
csum = [0] + list(accumulate(arr))
ans = 0
tmp = 0
for i in range(0, len(csum), 2):
    l = i
    r = min(i + 2 * K + 1, len(csum) - 1)
    tmp = csum[r] - csum[l] - (r == len(csum) - 1) - (l == 0) - (l == 1)
    ans = max(ans, tmp)
if len(csum) == 2:
    print((csum[1] - 2))
else:
    print(ans)

+from itertools import accumulate + -csum = [0] * (len(arr) + 1) -for i in range(len(arr)): -    csum[i + 1] = csum[i] + arr[i] +csum = [0] + list(accumulate(arr))