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

S = eval(input())

 

l = [[], []]

ans = []

k = [int(s) for s in S]

if k[0] == 0:

    l[1].append(0)

v0 = 1 if k[0] == 0 else 0

v1 = 1 if k[0] == 1 else 0

for i in range(1, N):

    if (k[i]==0) & (k[i-1]==0):

        v0 += 1

    elif (k[i]==1) & (k[i-1]==0):

        l[0].append(v0)

        v0 = 0

        v1 += 1

    elif (k[i]==0) & (k[i-1]==1):

        l[1].append(v1)

        v0 += 1

        v1 = 0 

    else:

        v1 += 1

        

for i, v in enumerate([v0, v1]):

    if v > 0:

        l[i].append(v)

        

if k[0] == 0:

    l[1].append(0)

    

l[0] += [0]*(K+1)

l[1] += [0]*(K+1)

a = sum(l[0][:K]) + sum(l[1][:K+1])

ans.append(a)

for i in range(1, len(l[0])-K-1):

    a -= l[0][i-1] + l[1][i-1]

    a += l[0][i+K-1] + l[1][i+K]

    ans.append(a)

print((max(ans)))
import sys

from collections import deque

input = sys.stdin.readline





def main():

    n,k = list(map(int,input().split()))

    s = list(eval(input()))



    #tank: '0...0'と'1...1'の塊の数リスト

    #ex. 0001011ならtank = [3,1,1,2] (0が3つ,1が1つ,0が2つ,1が2つ)

    tank = []

    cnt = 1

    for i in range(1,n):

        if s[i] != s[i-1]:

            tank.append(cnt)

            cnt = 0

        cnt += 1

        if i == n-1:

            tank.append(cnt)

    #p:tankの長さ

    p = len(tank)



    #全部1にできてしまう場合

    if s[0] == '0' and (p+1)//2 <= k:

        print(n)

        exit()

    if p//2 <= k and s[0] == '1':

        print(n)

        exit()



    

    ans = 0

    #res:tank[j]が1...1の右端の時の解

    res = 0

    if s[0] == '0':

        for j in range(2*k):

            res += tank[j]

        ans = res

        for j in range(2*k,p):

            if j == 2*k:

                res -= tank[0]

            elif j%2 == 0:

                res= res - tank[j-2*k] -tank[j-2*k-1]

            res += tank[j]

            ans = max(ans,res)



    else:

        for j in range(2*k+1):

            res += tank[j]

        ans = res

        for j in range(2*k+1,p):

            if j % 2 == 1:

                res = res- tank[j-2*k-1]-tank[j-2*k]

            res += tank[j]

            ans = max(ans,res)



    print(ans)



if __name__ == '__main__':

    main()
N, K = list(map(int, input().split()))
S = eval(input())
l = [[], []]
ans = []
k = [int(s) for s in S]
if k[0] == 0:
    l[1].append(0)
v0 = 1 if k[0] == 0 else 0
v1 = 1 if k[0] == 1 else 0
for i in range(1, N):
    if (k[i] == 0) & (k[i - 1] == 0):
        v0 += 1
    elif (k[i] == 1) & (k[i - 1] == 0):
        l[0].append(v0)
        v0 = 0
        v1 += 1
    elif (k[i] == 0) & (k[i - 1] == 1):
        l[1].append(v1)
        v0 += 1
        v1 = 0
    else:
        v1 += 1
for i, v in enumerate([v0, v1]):
    if v > 0:
        l[i].append(v)
if k[0] == 0:
    l[1].append(0)
l[0] += [0] * (K + 1)
l[1] += [0] * (K + 1)
a = sum(l[0][:K]) + sum(l[1][: K + 1])
ans.append(a)
for i in range(1, len(l[0]) - K - 1):
    a -= l[0][i - 1] + l[1][i - 1]
    a += l[0][i + K - 1] + l[1][i + K]
    ans.append(a)
print((max(ans)))

import sys
from collections import deque

input = sys.stdin.readline


def main():
    n, k = list(map(int, input().split()))
    s = list(eval(input()))
    # tank: '0...0'と'1...1'の塊の数リスト
    # ex. 0001011ならtank = [3,1,1,2] (0が3つ,1が1つ,0が2つ,1が2つ)
    tank = []
    cnt = 1
    for i in range(1, n):
        if s[i] != s[i - 1]:
            tank.append(cnt)
            cnt = 0
        cnt += 1
        if i == n - 1:
            tank.append(cnt)
    # p:tankの長さ
    p = len(tank)
    # 全部1にできてしまう場合
    if s[0] == "0" and (p + 1) // 2 <= k:
        print(n)
        exit()
    if p // 2 <= k and s[0] == "1":
        print(n)
        exit()
    ans = 0
    # res:tank[j]が1...1の右端の時の解
    res = 0
    if s[0] == "0":
        for j in range(2 * k):
            res += tank[j]
        ans = res
        for j in range(2 * k, p):
            if j == 2 * k:
                res -= tank[0]
            elif j % 2 == 0:
                res = res - tank[j - 2 * k] - tank[j - 2 * k - 1]
            res += tank[j]
            ans = max(ans, res)
    else:
        for j in range(2 * k + 1):
            res += tank[j]
        ans = res
        for j in range(2 * k + 1, p):
            if j % 2 == 1:
                res = res - tank[j - 2 * k - 1] - tank[j - 2 * k]
            res += tank[j]
            ans = max(ans, res)
    print(ans)


if __name__ == "__main__":
    main()

-N, K = list(map(int, input().split())) -S = eval(input()) -l = [[], []] -ans = [] -k = [int(s) for s in S] -if k[0] == 0: -    l[1].append(0) -v0 = 1 if k[0] == 0 else 0 -v1 = 1 if k[0] == 1 else 0 -for i in range(1, N): -    if (k[i] == 0) & (k[i - 1] == 0): -        v0 += 1 -    elif (k[i] == 1) & (k[i - 1] == 0): -        l[0].append(v0) -        v0 = 0 -        v1 += 1 -    elif (k[i] == 0) & (k[i - 1] == 1): -        l[1].append(v1) -        v0 += 1 -        v1 = 0 +import sys +from collections import deque + +input = sys.stdin.readline + + +def main(): +    n, k = list(map(int, input().split())) +    s = list(eval(input())) +    # tank: '0...0'と'1...1'の塊の数リスト +    # ex. 0001011ならtank = [3,1,1,2] (0が3つ,1が1つ,0が2つ,1が2つ) +    tank = [] +    cnt = 1 +    for i in range(1, n): +        if s[i] != s[i - 1]: +            tank.append(cnt) +            cnt = 0 +        cnt += 1 +        if i == n - 1: +            tank.append(cnt) +    # p:tankの長さ +    p = len(tank) +    # 全部1にできてしまう場合 +    if s[0] == "0" and (p + 1) // 2 <= k: +        print(n) +        exit() +    if p // 2 <= k and s[0] == "1": +        print(n) +        exit() +    ans = 0 +    # res:tank[j]が1...1の右端の時の解 +    res = 0 +    if s[0] == "0": +        for j in range(2 * k): +            res += tank[j] +        ans = res +        for j in range(2 * k, p): +            if j == 2 * k: +                res -= tank[0] +            elif j % 2 == 0: +                res = res - tank[j - 2 * k] - tank[j - 2 * k - 1] +            res += tank[j] +            ans = max(ans, res) -        v1 += 1 -for i, v in enumerate([v0, v1]): -    if v > 0: -        l[i].append(v) -if k[0] == 0: -    l[1].append(0) -l[0] += [0] * (K + 1) -l[1] += [0] * (K + 1) -a = sum(l[0][:K]) + sum(l[1][: K + 1]) -ans.append(a) -for i in range(1, len(l[0]) - K - 1): -    a -= l[0][i - 1] + l[1][i - 1] -    a += l[0][i + K - 1] + l[1][i + K] -    ans.append(a) -print((max(ans))) +        for j in range(2 * k + 1): +            res += tank[j] +        ans = res +        for j in range(2 * k + 1, p): +            if j % 2 == 1: +                res = res - tank[j - 2 * k - 1] - tank[j - 2 * k] +            res += tank[j] +            ans = max(ans, res) +    print(ans) + + +if __name__ == "__main__": +    main()