n,k = [int(i) for i in input().split()]

s = eval(input())



if s[0] == "1":

    retu = "whiteblack"

else:

    retu = "blackwhite"





count = 0

pre_person = s[0]

groups = []

for i in range(n):

    person = s[i]



    if person != pre_person:

        groups.append(count)

        count = 0

        pre_person = person

    count += 1

groups.append(count)





maxscore1 = 0

if retu == "whiteblack":

    score1 = 0

    blackgroups = len(groups)//2

    if k < blackgroups:

        start_index = 1

        score1 = groups[start_index-1]

        for j in range(k):

            score1 += groups[start_index+2*j]

            if start_index + 2*j+1 < len(groups):

                score1 += groups[start_index+2*j+1]

        maxscore1 = max(score1, maxscore1)

        for i in range(blackgroups - k):

            score1 -= groups[start_index + 2*i - 1]

            score1 -= groups[start_index + 2*i]

            score1 += groups[start_index + 2*k +2*i]

            if start_index+2*k+1+2*i < len(groups):

                score1 += groups[start_index + 2 * k +1 + 2 * i]

            maxscore1 = max(score1, maxscore1)

    else:

        maxscore1 = n



else:

    score1 = 0

    blackgroups = len(groups) - len(groups)//2

    if k < blackgroups:

        start_index = 0

        score1 = 0

        for j in range(k):

            score1 += groups[start_index+2*j]

            if start_index + 2*j+1 < len(groups):

                score1 += groups[start_index+2*j+1]



        maxscore1 = max(score1, maxscore1)

        for i in range(blackgroups - k):

            if i >=1:

                score1 -= groups[start_index + 2*i - 1]

            score1 -= groups[start_index + 2*i]

            score1 += groups[start_index + 2*k +2*i]

            if start_index+2*k+1+2*i < len(groups):

                score1 += groups[start_index + 2 * k + 1 + 2 * i]



            maxscore1 = max(score1, maxscore1)

    else:

        maxscore1 = n



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

s=eval(input())



ruiwa = [0]



for i in range(1,len(s)):

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

        ruiwa.append(i)

ruiwa.append(n)



if s[0] == "1":

    ans = ruiwa[1]

    if ((len(ruiwa) - 1) // 2) <= k:

        ans = n

    else:

        for i in range(((len(ruiwa)-1)//2)-k+1):

            ans = max(ans,ruiwa[min(2*k+1+2*i,len(ruiwa)-1)] - ruiwa[2*i])

else:

    ans = 0

    if len(ruiwa) - 1 - (len(ruiwa) - 1) // 2 <= k:

        ans = n

    else:

        for i in range(len(ruiwa) - 1 - (len(ruiwa)-1)//2 - k + 1):

            ans = max(ans, ruiwa[min(2*k+2*i, len(ruiwa)-1)] - ruiwa[max(0,2*i-1)])



print(ans)
n, k = [int(i) for i in input().split()]
s = eval(input())
if s[0] == "1":
    retu = "whiteblack"
else:
    retu = "blackwhite"
count = 0
pre_person = s[0]
groups = []
for i in range(n):
    person = s[i]
    if person != pre_person:
        groups.append(count)
        count = 0
        pre_person = person
    count += 1
groups.append(count)
maxscore1 = 0
if retu == "whiteblack":
    score1 = 0
    blackgroups = len(groups) // 2
    if k < blackgroups:
        start_index = 1
        score1 = groups[start_index - 1]
        for j in range(k):
            score1 += groups[start_index + 2 * j]
            if start_index + 2 * j + 1 < len(groups):
                score1 += groups[start_index + 2 * j + 1]
        maxscore1 = max(score1, maxscore1)
        for i in range(blackgroups - k):
            score1 -= groups[start_index + 2 * i - 1]
            score1 -= groups[start_index + 2 * i]
            score1 += groups[start_index + 2 * k + 2 * i]
            if start_index + 2 * k + 1 + 2 * i < len(groups):
                score1 += groups[start_index + 2 * k + 1 + 2 * i]
            maxscore1 = max(score1, maxscore1)
    else:
        maxscore1 = n
else:
    score1 = 0
    blackgroups = len(groups) - len(groups) // 2
    if k < blackgroups:
        start_index = 0
        score1 = 0
        for j in range(k):
            score1 += groups[start_index + 2 * j]
            if start_index + 2 * j + 1 < len(groups):
                score1 += groups[start_index + 2 * j + 1]
        maxscore1 = max(score1, maxscore1)
        for i in range(blackgroups - k):
            if i >= 1:
                score1 -= groups[start_index + 2 * i - 1]
            score1 -= groups[start_index + 2 * i]
            score1 += groups[start_index + 2 * k + 2 * i]
            if start_index + 2 * k + 1 + 2 * i < len(groups):
                score1 += groups[start_index + 2 * k + 1 + 2 * i]
            maxscore1 = max(score1, maxscore1)
    else:
        maxscore1 = n
print(maxscore1)

n, k = list(map(int, input().split()))
s = eval(input())
ruiwa = [0]
for i in range(1, len(s)):
    if s[i] != s[i - 1]:
        ruiwa.append(i)
ruiwa.append(n)
if s[0] == "1":
    ans = ruiwa[1]
    if ((len(ruiwa) - 1) // 2) <= k:
        ans = n
    else:
        for i in range(((len(ruiwa) - 1) // 2) - k + 1):
            ans = max(ans, ruiwa[min(2 * k + 1 + 2 * i, len(ruiwa) - 1)] - ruiwa[2 * i])
else:
    ans = 0
    if len(ruiwa) - 1 - (len(ruiwa) - 1) // 2 <= k:
        ans = n
    else:
        for i in range(len(ruiwa) - 1 - (len(ruiwa) - 1) // 2 - k + 1):
            ans = max(
                ans,
                ruiwa[min(2 * k + 2 * i, len(ruiwa) - 1)] - ruiwa[max(0, 2 * i - 1)],
            )
print(ans)

-n, k = [int(i) for i in input().split()] +n, k = list(map(int, input().split())) +ruiwa = [0] +for i in range(1, len(s)): +    if s[i] != s[i - 1]: +        ruiwa.append(i) +ruiwa.append(n) -    retu = "whiteblack" +    ans = ruiwa[1] +    if ((len(ruiwa) - 1) // 2) <= k: +        ans = n +    else: +        for i in range(((len(ruiwa) - 1) // 2) - k + 1): +            ans = max(ans, ruiwa[min(2 * k + 1 + 2 * i, len(ruiwa) - 1)] - ruiwa[2 * i]) -    retu = "blackwhite" -count = 0 -pre_person = s[0] -groups = [] -for i in range(n): -    person = s[i] -    if person != pre_person: -        groups.append(count) -        count = 0 -        pre_person = person -    count += 1 -groups.append(count) -maxscore1 = 0 -if retu == "whiteblack": -    score1 = 0 -    blackgroups = len(groups) // 2 -    if k < blackgroups: -        start_index = 1 -        score1 = groups[start_index - 1] -        for j in range(k): -            score1 += groups[start_index + 2 * j] -            if start_index + 2 * j + 1 < len(groups): -                score1 += groups[start_index + 2 * j + 1] -        maxscore1 = max(score1, maxscore1) -        for i in range(blackgroups - k): -            score1 -= groups[start_index + 2 * i - 1] -            score1 -= groups[start_index + 2 * i] -            score1 += groups[start_index + 2 * k + 2 * i] -            if start_index + 2 * k + 1 + 2 * i < len(groups): -                score1 += groups[start_index + 2 * k + 1 + 2 * i] -            maxscore1 = max(score1, maxscore1) +    ans = 0 +    if len(ruiwa) - 1 - (len(ruiwa) - 1) // 2 <= k: +        ans = n -        maxscore1 = n -else: -    score1 = 0 -    blackgroups = len(groups) - len(groups) // 2 -    if k < blackgroups: -        start_index = 0 -        score1 = 0 -        for j in range(k): -            score1 += groups[start_index + 2 * j] -            if start_index + 2 * j + 1 < len(groups): -                score1 += groups[start_index + 2 * j + 1] -        maxscore1 = max(score1, maxscore1) -        for i in range(blackgroups - k): -            if i >= 1: -                score1 -= groups[start_index + 2 * i - 1] -            score1 -= groups[start_index + 2 * i] -            score1 += groups[start_index + 2 * k + 2 * i] -            if start_index + 2 * k + 1 + 2 * i < len(groups): -                score1 += groups[start_index + 2 * k + 1 + 2 * i] -            maxscore1 = max(score1, maxscore1) -    else: -        maxscore1 = n -print(maxscore1) +        for i in range(len(ruiwa) - 1 - (len(ruiwa) - 1) // 2 - k + 1): +            ans = max( +                ans, +                ruiwa[min(2 * k + 2 * i, len(ruiwa) - 1)] - ruiwa[max(0, 2 * i - 1)], +            ) +print(ans)