N people are arranged in a row from left to right.
You are given a string S of length N consisting of 0 and 1, and a positive integer K.
The i-th person from the left is standing on feet if the i-th character of S is 0, and standing on hands if that character is 1.
You will give the following direction at most K times (possibly zero):
Direction: Choose integers l and r satisfying 1 \leq l \leq r \leq N, and flip the l-th, (l+1)-th, ..., and r-th persons. That is, for each i = l, l+1, ..., r, the i-th person from the left now stands on hands if he/she was standing on feet, and stands on feet if he/she was standing on hands.
Find the maximum possible number of consecutive people standing on hands after at most K directions.

-----Constraints-----
 - N is an integer satisfying 1 \leq N \leq 10^5.
 - K is an integer satisfying 1 \leq K \leq 10^5.
 - The length of the string S is N.
 - Each character of the string S is 0 or 1.

-----Input-----
Input is given from Standard Input in the following format:
N K
S

-----Output-----
Print the maximum possible number of consecutive people standing on hands after at most K directions.

-----Sample Input-----
5 1
00010

-----Sample Output-----
4

We can have four consecutive people standing on hands, which is the maximum result, by giving the following direction:
 - Give the direction with l = 1, r = 3, which flips the first, second and third persons from the left.

Difficulty: interview

Starter code:

Solutions:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, K, S):
    S = [int(s) for s in S]
    point_l = 0
    point_r = 0
    # decision r
    num_0 = 0 if S[0] == 1 else 1
    flg = S[0]
    for i in range(N):
        if S[i] != flg:
            if flg == 1:
                num_0 += 1
                if num_0 > K:
                    point_r = i - 1
                    break
            flg = S[i]
        if i == N - 1:
            point_r = i
            break
    # measuring method
    ans = point_r - point_l + 1
    while point_r < N - 1:
        # move point_l
        for i in range(0, N):
            if S[point_l + i] != S[point_l + i + 1]:
                if S[point_l + i + 1] == 1:
                    point_l += i + 1
                    break
        # move point_r
        for i in range(1, N):
            if point_r + i == N - 1:
                point_r = N - 1
                break
            if S[point_r + i] != S[point_r + i + 1]:
                if S[point_r + i + 1] == 0:
                    point_r += i
                    break
        ans = max(ans, point_r - point_l + 1)

    print(ans)


def __starting_point():
    N, K = list(map(int, input().split()))
    S = input()
    solve(N, K, S)

    # # test
    # from random import randint
    # from func import random_str
    # solve()

__starting_point()

n,k = map(int,input().split())
s = input()
I  = [0]
for i in range(1,n):
    if s[i-1] != s[i]:
        I.append(i)
I.append(n)
r = len(I)-1
X = []
for i in range(r):
    if s[I[i]] == "0":
        X.append(I[min(2*k+i,r)]-I[i])
    else:
        X.append(I[min(2*k+1+i,r)]-I[i])
print(max(X))

"""
keyword: 尺取法
"""

import sys
sys.setrecursionlimit(10**6)

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

nums = []
now = 1 # 今見ている数
cnt = 0 # nowがいくつ並んでいるか

for i in range(n):
    if s[i] == str(now):
        cnt += 1
    else:
        nums.append(cnt)
        now ^= 1 # 0と1を切り替える
        cnt = 1 # 新しいのをカウント
if cnt != 0:
    nums.append(cnt)

# 1-0-1-0-1-0-1って感じの配列が欲しい
# 1-0-1-0みたいに0で終わっていたら、適当に1つ足す
# 補足：1-0-1-0-1というのは、1が0個、0が2個、1が1個、、、などと並んでいるという意味。このとき1つ目の0をひっくり返すと1-1-1と連続する。1-...-1と連続している数が求める値なので、左端と右端は1にしたい
if len(nums)%2 == 0:
    nums.append(0)
    
add = 2*k+1

ans = 0
left = 0
right = 0
tmp = 0 # [left, right)のsum

# 1-0-1...の、1から始まり1で終わる範囲を見るので、偶数番目だけ見る
for i in range(0, len(nums), 2):
    
    nextleft = i
    nextright = min(i+add, len(nums))
    
    # 左端を移動
    while (nextleft > left):
        tmp -= nums[left]
        left += 1
    # 右端を移動
    while (nextright > right):
        tmp += nums[right]
        right += 1
        
    ans = max(tmp, ans)
    
print(ans)

from collections import *
n,k=map(int,input().split())
s=input()
q=deque()
tt=0
f=False
t=0
ans=0
tmp=0
for i in range(n):
    if f:
        if s[i]=="0":
            tmp+=1
            tt+=1
            if tmp>ans:
                ans=tmp
        else:
            q.append(tt)
            f=False
            tt=1
            tmp+=1
            if tmp>ans:
                ans=tmp

    elif f==False:
        if s[i]=="1":
            tmp+=1
            tt+=1
            if tmp>ans:
                ans=tmp
        else:
            t+=1
            f=True
            if t>k:
                d=q.popleft()
                tmp-=d
            tmp+=1
            tt+=1
print(ans)

#!/usr/bin/env python3
import sys

def f(S):
    c, n = S[0], 1
    for cc in S[1:]:
        if c == cc:
            n += 1
        else:
            yield c, n
            c, n = cc, 1
    yield c, n

def solve(N: int, K: int, S: str):
    from itertools import zip_longest
    A = list(f(S))
    M = len(A)
    i, j, k, su, ans = 0, 0, 0, 0, 0
    while i < M:
        while j < M and (k < K or A[j][0] == "1"):
            su += A[j][1]
            k += 1 if A[j][0] == "0" else 0
            j += 1
        ans = max(ans, su)        
        su -= A[i][1]
        k -= 1 if A[i][0] == "0" else 0
        i += 1        
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print((solve(N, K, S)))

def test():
    import doctest
    doctest.testmod()

def __starting_point():
    #test()
    main()

__starting_point()

n, k = map(int, input().split())
s = input()
ls = []

now = 1
cnt = 0
for ele in s:
    if int(ele) == now:
        cnt += 1
    else:
        ls.append(cnt)
        now = 1 - now #1と0の切替
        cnt = 1
ls.append(cnt)

# 1-0-1-0-1が欲しい
# 1-0-1-0の場合、1の場合を足す
if len(ls) % 2 == 0:
    ls.append(0)

Add = 2*k+1 #[left, right)
ans = 0

left = 0
right = 0
tmp = 0 # [left, right)のsum

# print(ls)
# 1-0-1-0..の１から始める
for i in range(0,len(ls),2):
    nextLeft = i
    nextRight = min(i + Add, len(ls))
    # print(" value", tmp)
    # print(" p left ", left)
    # print(" p right", right)

    while nextLeft > left:
        # print("left  point, value", left, tmp)
        tmp -= ls[left]
        left += 1
    while nextRight > right:
        # print("right point, value", right, tmp)
        tmp += ls[right]
        right += 1

    ans = max(tmp, ans)
    # print("ans",ans)
    # print("\n")

print(ans)

N,K=map(int,input().split())
S=input()
A=[]
now=S[0]
if now=='0':
    A.append(0)
C=1
for s in S[1:]:
    if s==now:
        C+=1
    else:
        A.append(C)
        now=s
        C=1
A.append(C)
if now=='0':
    A.append(0)
B=[sum(A[:2*K+1])]
i=0
while 2*(i+K+1)<len(A):
    b=B[i]-(A[2*i]+A[2*i+1])+(A[2*(i+K+1)]+A[2*(i+K)+1])
    B.append(b)
    i+=1
print(max(B))

N,K=map(int,input().split())
S=[int(i) for i in input()]
ans,r,l,k=0,0,0,K
while r<N:
  while k>0:
    while l<N and S[l]==1:
      l+=1
    while l<N and S[l]==0:
      l+=1
    k-=1
  while l<N and S[l]==1:
    l+=1
  ans=max(ans,l-r)
  while r<N and S[r]==1:
    r+=1
  while r<N and S[r]==0:
    r+=1
  k=1
print(ans)

def main():
	N, K = [int(x) for x in input().split(" ")]
	S = list(input())
	cnt = [0] # idx = 0, 2, 4 ... -> handstand
	a = 0
	for i in range(len(S)):
		if S[i] == "0":
			if a % 2 == 0:
				a += 1
				cnt.append(1)
			else:
				cnt[-1] += 1
		elif S[i] == "1":
			if a % 2 == 0:
				cnt[-1] += 1
			else:
				a += 1
				cnt.append(1)
	if S[-1] == "0":
		cnt.append(0)

	if K >= (len(cnt) - 1) / 2:
		print(N)
		return 0

	T = [sum(cnt[:(2 * K + 1)])]
	for i in range(0, len(cnt) - 2 * K - 2, 2):
		T.append(T[-1] - cnt[i] - cnt[i + 1] + cnt[i + 2 * K + 1] + cnt[i + 2 * K + 2])
	print(max(T))

main()

from itertools import *
from numpy import *
n,k = map(int,input().split())
k = 2*k+1
s = input()
x = [0]*(s[0]=="0")+[len(list(v))for k,v in groupby(s)]+[0]*(s[-1]=="0")
x1 = array(x[k:])
x2 = array(x[:-k])
x3 = sum(x[:k])
y = [x3]+list(x3+cumsum(x1-x2))
print(max(y[::2]))

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

# 1の個数, 0の個数, 1の個数, ..., 1の個数
list10 = []
head = S[0]
cnt = 0

# 左端の1の数
if S[0] == "0":
    list10.append(0)

for i in range(N):
    if S[i] == head:
        cnt += 1
    else:
        list10.append(cnt)
        cnt = 1
        head = S[i]

    if i == N - 1:
        list10.append(cnt)

# 右端の1の数
if S[-1] == "0":
    list10.append(0)

# print(list10)

ans = 0

cumsum = [0]
for li in list10:
    cumsum.append(cumsum[-1] + li)
# print(cumsum)

for j in range(1, len(cumsum), 2):
    h = j
    t = min(j + 2 * K, len(cumsum) - 1)
    ans = max(ans, cumsum[t] - cumsum[max(h - 1, 0)])
print(ans)


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

def rle(string):
    _rle_str = string[0]
    _rle_cnt = 1
    _ans_l = []
    for _i in range(1, len(string)):
        if _rle_str == string[_i]:
            _rle_cnt += 1
        else:
            _ans_l.append([_rle_str, _rle_cnt])
            _rle_str = string[_i]
            _rle_cnt = 1
    _ans_l.append([_rle_str, _rle_cnt])
    return _ans_l

rle_s=rle(s)

ans=-1

left=0
wa=0

if rle_s[0][0]=="0":
    cnt=1
    wa=rle_s[0][1]
    right=1
else:
    cnt=0
    right=0

if len(rle_s)==1 and k>=1:
    print((rle_s[0][1]))
    return

while right<len(rle_s):
    # print(right, left, wa, cnt)
    if cnt==k:
        if rle_s[right][0]=="0":
            if rle_s[left][0]=="0":
                wa-=rle_s[left][1]
                cnt-=1
            else:
                wa-=rle_s[left][1]
            left+=1

        else:
            wa+=rle_s[right][1]
            right+=1
            ans=max(ans, wa)

    elif cnt<k:
        if rle_s[right][0]=="0":
            cnt+=1
            wa+=rle_s[right][1]
        else:
            wa+=rle_s[right][1]
        right+=1
        ans=max(ans, wa)

    else:
        if rle_s[left][0]=="0":
            wa-=rle_s[left][1]
            cnt-=1
        else:
            wa-=rle_s[left][1]
        left+=1

print(ans)


#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, K = map(int, input().split())
    S = input()
    A = []
    if S[0]=='1':
        nw = 1
    else:
        nw = -1
    for i in range(1,N):
        if S[i]=='1' and nw<0:
            A.append(nw)
            nw = 1
        elif S[i]=='0' and nw>0:
            A.append(nw)
            nw = -1
        else:
            nw += 2*(S[i]=='1')-1
    A.append(nw)
    if len(A)==1:
        print(N)
        return
    B = [0]*(len(A)+1)
    for i in range(len(A)):
        B[i+1] = B[i]+abs(A[i])
    if A[0]<0:
        fm = 0
    else:
        fm = 1
    ret = 0
    for i in range(fm, len(A), 2):
        ret = max(ret, B[min(i+2*K,len(B)-1)]-B[max(i-1,0)])
    print(ret)

def __starting_point():
    main()
__starting_point()

n,k=map(int,input().split())
s=[int(i) for i in input()]
l1,l0=[],[]
b,c=1,0
for i in s:
  if b==i: c+=1
  else:
    if b: l1+=[c]
    else: l0+=[c]
    c=1
  b=i
if b:
  l1+=[c]
  l0+=[0]
else:
  l0+=[c]
S=[0]
for i,j in zip(l1,l0):
  S+=[S[-1]+i+j]
l1+=[0]
m=len(S)
if m<=k:
  print(n)
  return
a=0
for i in range(k,m):
  a=max(a,S[i]-S[i-k]+l1[i])
print(a)

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

N,K=list(map(int,input().split()))
S=input()
a=[0]
for i in range(1,N):
  if S[i-1]!=S[i]:
    a.append(i)
a.append(N)
l=len(a)
ans=[]
for i in range(l-1):
  if S[a[i]]=='0':
    ans.append(a[min(i+2*K,l-1)]-a[i])
  else:
    ans.append(a[min(i+2*K+1,l-1)]-a[i])
print((max(ans)))


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

if N==1:
  print(1)
  return

S2=[]
signs=[]
if S[0]=='1':
  sign=1
else:
  sign=0
count = 1
for i in range(1,N):
  if S[i] != S[i-1]:
    S2.append(count)
    signs.append(sign)
    sign = 1- sign
    count = 0
  count += 1
  
S2.append(count)
signs.append(sign)
  
cumS = [0]
for i in range(len(S2)):
  cumS.append(cumS[-1]+S2[i])
  
k = K*2+1
if len(S2)>=k:
  MAX=0
  for i in range(len(S2)-k+1):
    if signs[i] == 1:
      tmp = cumS[i+k]-cumS[i]
      if tmp > MAX:
        MAX = tmp
  
  if signs[0]==0:
    MAX = max(MAX,cumS[k-1]-cumS[0])
  if signs[-1]==0:
    MAX = max(MAX,cumS[-1]-cumS[-k])
    
else:
  MAX=cumS[-1]
  
print(MAX)

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

arr = []

if S[0] == '0':
    arr.append(0)

cnt = 0
for i in range(N - 1):
    if S[i] == S[i + 1]:
        cnt += 1
    else:
        arr.append(cnt + 1)
        cnt = 0
arr.append(cnt + 1)

if S[-1] == '0':
    arr.append(0)

res = 0
s = 0
i = 0
while i < 2 * K + 1 and i < len(arr):
    s += arr[i]
    i += 1

res = s

while i < len(arr) - 1:
    s += arr[i] + arr[i + 1] - arr[i - 2 * K - 1] - arr[i - 2 * K]
    res = max(s, res)

    i += 2

print(res)

N, K = map(int, input().split())
s = str(input())
  
l = []
tmp, cnt = s[0], 1
for i in range(1, N):
  if s[i] == tmp:
    cnt += 1
  else:
    tmp = s[i]
    l.append(cnt)
    cnt = 1
l.append(cnt)

start, goal = 0, len(l)
if s[0] == '0':
  start += 1
if s[-1] == '0':
  goal -= 1
  
ans = sum(l[start:start+2*K+1])
tmp = ans
for i in range(start, goal-2*K-2, 2):
  tmp += l[i+2*K+1]+l[i+2*K+2]-l[i]-l[i+1]
  ans = max(ans, tmp)
if ans < sum(l[:2*K]):
  ans = sum(l[:2*K])
if ans < sum(l[-2*K:]):
  ans = sum(l[-2*K:])
print(ans)

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

if "0" not in S:
    print(n)
    return

# 1の個数、0の個数、1の個数、、、
cnt = []

# 先頭が0なら1が0個とみなす
if S[0] == "0":
    cnt.append(0)

# 個数勘定
i = 0
while i < n:
    j = i
    while j < n and S[i] == S[j]:
        j += 1
    cnt.append(j-i)
    i = j

# 最後尾が0なら1が0個とみなす
if S[-1] == "0":
    cnt.append(0)

# cnt の累積和
cumCnt = [0]
for c in cnt:
    cumCnt.append(cumCnt[-1] + c)

# print(cnt)
# print(cumCnt)

lenCnt = len(cnt)
lenCumCnt = len(cumCnt)
ans = 0

for left in range(0, lenCumCnt, 2):
    right = min(left + 2*k+1, lenCumCnt-1)
    ans = max(ans, cumCnt[right] - cumCnt[left])
print(ans)

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

nums = []
if s[0] == '0':
    nums.append(0)
i = 0
while i < n:
    j = i
    while j < n and s[j] == s[i]:
        j += 1
    nums.append(j-i)
    i = j
if s[-1] == '0':
    nums.append(0)

sums = [0]
for i in range(len(nums)):
    sums.append(sums[-1]+nums[i])

res = 0
for left in range(0, len(sums), 2):
    right = left + k*2+1
    if right >= len(sums):
        right = len(sums) - 1
    res = max(res, sums[right]-sums[left])
print(res)

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

beforeChar = S[0]
sectionList = []
count = 0
for i in range(N):
    if S[i] == beforeChar:
        count += 1
    else:
        sectionList.append([beforeChar, count])
        count = 1
        beforeChar = S[i]
sectionList.append([beforeChar, count])

sectionNumber = len(sectionList)
zeroSectionNumber = 0
oneSectionNumber = 0
if sectionNumber % 2 == 0:
    zeroSectionNumber = sectionNumber // 2
    oneSectionNumber = sectionNumber // 2
else:
    if sectionList[0][0] == '0':
        zeroSectionNumber = sectionNumber // 2 + 1
        oneSectionNumber = sectionNumber // 2
    else:
        zeroSectionNumber = sectionNumber // 2
        oneSectionNumber = sectionNumber // 2 + 1

if zeroSectionNumber <= K:
    print(N)
    return

sumLengthList = []
sumLength = 0
for i in range(sectionNumber):
    sumLength += sectionList[i][1]
    sumLengthList.append(sumLength)

def sumLengthByRange(rangeStartSection, rangeEndSection):
    if rangeStartSection == 0:
        return sumLengthList[rangeEndSection]
    else:
        return sumLengthList[rangeEndSection] - sumLengthList[rangeStartSection - 1]

startSection = 0
endSection = 0
lengthList = []
if sectionList[0][0] == '1':
    endSection = K * 2
else:
    endSection = K * 2 - 1
    lengthList.append(sumLengthByRange(startSection, endSection))
    startSection = 1
    endSection += 2
while endSection < sectionNumber:
    lengthList.append(sumLengthByRange(startSection, endSection))
    startSection += 2
    endSection += 2
if sectionList[-1][0] == '0':
    endSection -= 1
    lengthList.append(sumLengthByRange(startSection, endSection))

print(max(lengthList))

import sys

icase=0
if icase==0:
    n,k=list(map(int,input().split()))
    s=input()

if n==1:
    print((1))
    return

ss=[]
if s[0]=="1" and s[1]=="1":
    zcnt=1
elif s[0]=="1" and s[1]=="0":
#    ss.append(1)
    zcnt=1
elif s[0]=="0" and s[1]=="0":
    ss.append(0)
    zcnt=1
elif s[0]=="0" and s[1]=="1":
    ss.append(0)
#    ss.append(1)
    zcnt=1

for i in range(1,n-1):
    if s[i]=="0" and s[i-1]=="0":
        zcnt+=1
    elif s[i]=="0" and s[i-1]=="1":
        ss.append(zcnt)
        zcnt=1
    elif s[i]=="1" and s[i-1]=="1":
        zcnt+=1
    elif s[i]=="1" and s[i-1]=="0":
        ss.append(zcnt)
        zcnt=1
        
for i in range(n-1,n):
    if s[i]=="0" and s[i-1]=="0":
        zcnt+=1
        ss.append(zcnt)
        ss.append(0)
    elif s[i]=="0" and s[i-1]=="1":
        ss.append(zcnt)
        ss.append(1)
        ss.append(0)
    elif s[i]=="1" and s[i-1]=="1":
        zcnt+=1
        ss.append(zcnt)
    elif s[i]=="1" and s[i-1]=="0":
        ss.append(zcnt)
        ss.append(1)

#print(ss)

if len(ss)<=2*k+1:
    print(n)
    return

smax=0
for i in range(2*k+1):
    smax+=ss[i]
#print(smax)    
ssum=smax    
kk=2*k
for i in range(2,len(ss)-kk,2):
    ssum=ssum-ss[i-2]-ss[i-1]+ss[i+kk-1]+ss[i+kk]
    smax=max(smax,ssum)

print(smax)


def rle(string):
    _rle_str = string[0]
    _rle_cnt = 1
    _ans_l = []
    for _i in range(1, len(string)):
        if _rle_str == string[_i]:
            _rle_cnt += 1
        else:
            _ans_l.append([_rle_str, _rle_cnt])
            _rle_str = string[_i]
            _rle_cnt = 1
    _ans_l.append([_rle_str, _rle_cnt])
    return _ans_l

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

rs=rle(s)

if rs[0][0]=="0":
    cnt=1
    wa=rs[0][1]
    r=1
    l=0
else:
    cnt=0
    wa=0
    r=0
    l=0

ans=-1

if len(rs)==1:
    print((rs[0][1]))
    return

while r<len(rs):
    if cnt==k and rs[r][0]=="0":
        if rs[l][0]=="0":
            wa-=rs[l][1]
            cnt-=1
        else:
            wa-=rs[l][1]
        l+=1

    elif cnt<=k:
        if rs[r][0]=="0":
            cnt+=1
            wa+=rs[r][1]
        else:
            wa+=rs[r][1]
        r+=1
        ans=max(ans, wa)

    else:
        if rs[l][0]=="0":
            wa-=rs[l][1]
            cnt-=1
        else:
            wa-=rs[l][1]
        l+=1

print(ans)


#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

def main():
    N, K = list(map(int, input().split()))
    S = input()
    nums = []
    # 1の個数、0の個数を交互に記録していく
    if S[0] == '0': nums.append(0)
    i = 0
    while i < N:
        j = i
        while j < N and S[i]==S[j]:
            j += 1
        nums.append(j-i)
        i = j
    if S[-1] == '0': nums.append(0)
    # print(nums)
    nums = [0] + list(accumulate(nums))
    # print(nums)
    ans = 0
    
    for i in range(0,len(nums),2):
        # print(i)
        ans = max(ans,nums[min(i+2*K+1,len(nums)-1)]-nums[i])
    print(ans)
        

def __starting_point():
    main()

__starting_point()

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

num = []
temp = 0
count = 0
flag = True
while temp < len(s):
    if flag == True:
        if s[temp] == "1":
            count += 1
            temp += 1
        else:
            num.append(count)
            count = 1
            temp += 1
            flag = False
    else:
        if s[temp] == "0":
            count += 1
            temp += 1
        else:
            num.append(count)
            count = 1
            temp += 1
            flag = True
num.append(count)
num2 = [sum(num[:min(2 * k + 1, len(num))])]
temp = min(2 * k + 1, len(num))
temp2 = 0
while temp < len(num):
    temp3 = num2[-1] - num[temp2] - num[temp2 + 1] + num[temp]
    if temp + 1 < len(num):
        temp3 += num[temp + 1]
    temp += 2
    temp2 += 2
    num2.append(temp3)
print(max(num2))

#create date: 2020-07-03 22:02

import sys
stdin = sys.stdin
from itertools import groupby, accumulate

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, k = na()
    s = ns()
    a = list()
    if s[0] == "0":
        a.append(0)
    gr = groupby(s)
    for key, group in gr:
        a.append(len(list(group)))
    if s[-1] == "0":
        a.append(0)
    acum = list(accumulate(a))
    m = len(acum)
    l = 2*k + 1
    if m == 1:
        print(acum[0])
        return
    if l > m:
        print(acum[-1])
        return
    ans = acum[l-1]
    for i in range(0, m-l+1, 2):
        ans = max(ans, acum[i+l-1] - acum[i-1])
    print(ans)

def __starting_point():
    main()
__starting_point()

N,K = map(int,input().split())
s = input()
ls = []
i = 0
c = 0
while i < N and s[i] == "1":
    c += 1
    i += 1
if i==N:
    print(N)
    return
while i < N:
    l = c
    c = 0
    while i < N and s[i] == "0":
        c += 1
        i += 1
    m = c
    c = 0
    while i < N and s[i] == "1":
        c += 1
        i += 1
    r = c
    ls.append((l,m,r))
K = min(K, len(ls))
from itertools import accumulate
acc = list(accumulate([0]+ls, lambda x,y:x+y[1]+y[2]))
ans = 0
for i in range(len(ls)-K+1):
    ans = max(ans, acc[i+K]-acc[i]+ls[i][0])
print(ans)

N,K=map(int,input().split())
S=input()
A=[]
now=S[0]
if now=='0':
    A.append(0)
C=1
for s in S[1:]:
    if s==now:
        C+=1
    else:
        A.append(C)
        now=s
        C=1
A.append(C)
if now=='0':
    A.append(0)
B=[sum(A[:2*K+1])]
i=0
j=2*(K+1)
while j<len(A):
    b=B[-1]+sum(A[j-1:j+1])-sum(A[i:i+2])
    B.append(b)
    i+=2
    j+=2
print(max(B))

def main():
    n,k = list(map(int,input().split()))
    s = input()
    L = []
    if s[0]=='0':
        z=1
        l=0
    else:
        z=0
    for i in range(n):
        if s[i]=='0' and z==0:
            l = i
            z = 1
        elif s[i]=='1' and z==1:
            L.append([l,i-1])
            z=0
    if z==1:
        L.append([l,n-1])
    ans=0
    if len(L)<=k:
        ans=n
    else:
        l=0
        r=L[k][0]-1
        if r-l+1>ans:
            ans=r-l+1
        for i in range(1,len(L)-k):
            l=L[i-1][1]+1
            r=L[i+k][0]-1
            if r-l+1>ans:
                ans=r-l+1
        l=L[-k-1][1]+1
        r=n-1
        if r-l+1>ans:
            ans=r-l+1
    print(ans)

def __starting_point():
    main()

__starting_point()

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    S = SS()

    # 1の塊の長さと位置を調べる
    l = []
    if S[0] == '1':
        l.append(0)
    # 先端0の場合、一番左に長さ0の1の塊があるとする
    else:
        l.append(0)
        l.append(0)
    for i in range(N - 1):
        if S[i] == '0' and S[i+1] == '1':
            l.append(i + 1)
        elif S[i] == '1' and S[i+1] == '0':
            l.append(i + 1)
    if S[-1] == '1':
        l.append(N)
    # 後端0の場合、一番右に長さ0の1の塊があるとする
    else:
        l.append(N)
        l.append(N)

    ans = 0
    # 0の塊がK個以下の場合
    if len(l) // 2 - 1 < K:
        ans = N
    # 1の塊をK+1個くっつけた場合の長さを調べる
    else:
        for i in range(len(l) // 2 - K):
            ans = max(l[2*i+2*K+1] - l[2*i], ans)

    print(ans)

def __starting_point():
    resolve()

__starting_point()

n,k=list(map(int,input().split()))
s=input()
d=[]

if s[0] == "0":
  zero=True
  iti=False
else:
  iti=True
  zero=False

count=0
for i in range(0,len(s)):
  if zero and s[i]=="0":
    count+=1
  elif zero and s[i]=="1":
    d.append(count)
    iti=True
    zero=False
    count=1
  elif iti and s[i]=="0":
    d.append(count)
    zero=True
    iti=False
    count=1
  elif iti and s[i]=="1":
    count+=1
d.append(count)
d.append(0)
import itertools
acum = list(itertools.accumulate([0]+d))
#print(d)
#print(acum)
hantei=0
ans=0
if s[0]=="0":
  ks1=min(k*2,len(d))
  ks2=min(k*2+1,len(d))
else:
  ks1=min(k*2+1,len(d))
  ks2=min(k*2,len(d))
  
for i in range(0,len(d)-ks1+1,2):
  ans=max(acum[i+(ks1)]-acum[i],ans)
for i in range(1,len(d)-ks2+1,2):
  ans=max(acum[i+(ks2)]-acum[i],ans)
print(ans)


N,K=map(int,input().split())
S=input()
a=[0]
for i in range(1,N):
  if S[i-1]!=S[i]:
    a.append(i)
a.append(N)
l=len(a)
ans=[]
for i in range(l-1):
  if S[a[i]]=='0':
    ans.append(a[min(i+2*K,l-1)]-a[i])
  else:
    ans.append(a[min(i+2*K+1,l-1)]-a[i])
print(max(ans))

N, K = map(int, input().split())
S = input()+"2"
L = []
cnt = 0
temp = int(S[0])

for x in S:
  if temp == int(x):
    cnt += 1
  else:
    L.append(cnt)
    cnt = 1
    temp = int(x)

if S[0] == "0":
  Lcs = [0, 0]
else:
  Lcs = [0]

for x in L:
  Lcs.append(Lcs[-1] + x)
 
ans = Lcs[1]
N = len(Lcs)
i = 2

if i + 2*(K-1) > N-1:
  print(Lcs[-1])
else:
  while i + 2*(K-1) <= N-1:
    if i + 2*(K-1) == N-1:
      ans = max(ans, Lcs[i + 2*(K-1)]-Lcs[i-2])
    else:
      ans = max(ans, Lcs[i + 2*(K-1) +1]-Lcs[i-2])
    i += 2
  print(ans)

"""
keyword: 累積和
"""

import sys
sys.setrecursionlimit(10**6)

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

nums = []
now = 1 # 今見ている数
cnt = 0 # nowがいくつ並んでいるか

for i in range(n):
    if s[i] == str(now):
        cnt += 1
    else:
        nums.append(cnt)
        now ^= 1 # 0と1を切り替える
        cnt = 1 # 新しいのをカウント
if cnt != 0:
    nums.append(cnt)

# 1-0-1-0-1-0-1って感じの配列が欲しい
# 1-0-1-0みたいに0で終わっていたら、適当に1つ足す
# 補足：1-0-1-0-1というのは、1が0個、0が2個、1が1個、、、などと並んでいるという意味。このとき1つ目の0をひっくり返すと1-1-1と連続する。1-...-1と連続している数が求める値なので、左端と右端は1にしたい
if len(nums)%2 == 0:
    nums.append(0)
    
add = 2*k+1

# 累積和を作る
tot = [0]*(len(nums)+1)
for i in range(len(nums)):
    tot[i+1] = tot[i]+nums[i]

ans = 0

# 1-0-1...の、1から始まり1で終わる範囲を見るので、偶数番目だけ見る
for i in range(0, len(nums), 2):
    
    # 次のleft, rightを計算する
    left = i
    right = min(i+add, len(nums))
    tmp = tot[right] - tot[left]
    
    ans = max(tmp, ans)
    
print(ans)

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

S = S + 'E'   # 終端処理
ans = -1    # 答えの初期値（十分に小さい値）

# 立った人の連続の数
if (S[0] == '0'):
    stand = 1
else:
    stand = 0

L = 0
R = 0

# 尺取り法
while (R < N):
    # 右端を進めることが可能（立った人の連続の数がK以下）なら、右端を進める
    if (stand <= K):
        # 立った人の連続の数が増えるなら1足す
        if (S[R] == '1' and S[R + 1] == '0'):
            stand += 1
        # 答えの更新
        ans = max(ans, R - L + 1)
        R += 1
    # 進められない場合、左端と右端が同じなら両者を進める
    # 左端が右端を追い越さないための処理
    elif (L == R):
        L += 1
        R += 1
    # それ以外は左端のみを進める
    else:
        # 立った人の連続の数が減るなら1減らす
        if (S[L] == '0' and S[L + 1] == '1'):
            stand -= 1
        L += 1
        # 左端のみを進めた場合は答えを更新し得ない

print(ans)

N, K = map(int, input().split())
S = input()
Nums = []
now = 1 # 今見ている数
cnt = 0 # nowがいくつ並んでいるか
for i in range(N):
    if S[i] == str(now):
        cnt += 1
    else:
        Nums.append(cnt)
        now = 1 - now   # 0と1を切り替えるときの計算 now ^= 1
        cnt = 1
if cnt != 0:
    Nums.append(cnt)
# 1-0-1-0-1-0-1 って感じの配列が欲しい
# 1-0-1-0-1-0 みたいに0で終わっていたら適当に1つ足す
if len(Nums) % 2 == 0:
    Nums.append(0)

Add = 2 * K + 1
# 累積和を作る
# 0 1 2 3 4 5 6
#  0 1 2 3 4 5
sum = [0] * (len(Nums) + 1)
for i in range(len(Nums)):
    sum[i + 1] = sum[i] + Nums[i]
ans = 0
# 1-0-1... の1から始めるので、偶数番目だけ見る
for i in range(0, len(Nums), 2):
    # 次のleft, rightを計算する [left, right)
    left = i
    right = min(i + Add, len(Nums))
    tmp = sum[right] - sum[left]
    ans = max(tmp, ans)

print(ans)

n, k = list(map(int,input().split()))
s = input()
sento = 0
ketu = 0
tmp = '1'
zeroichi = []
cnt = 0

for i in range(n):
    if tmp == s[i]:
        cnt += 1
    else:
        zeroichi.append(cnt)
        cnt = 1
        tmp = s[i]

zeroichi.append(cnt)

if len(zeroichi)%2 == 0:
    zeroichi.append(0)

if len(zeroichi) == 1:
    zeroichi.append(0)
    zeroichi.append(0)

i = 0
ans = 0
ans_list = []
j = 0
right = min(1+k*2,len(zeroichi))
left = 0

while i != right:
    ans += zeroichi[i]
    i += 1

ans_list.append(ans)

while right != len(zeroichi):
    ans -= zeroichi[left]
    ans -= zeroichi[left+1]
    ans += zeroichi[right]
    ans += zeroichi[right+1]
    ans_list.append(ans)
    left += 2
    right += 2

print((max(ans_list)))


from itertools import groupby

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


grouped = groupby (s)
res = []

if s[0] == '0':
	res.append((1,0))

for l,v in grouped:
	res.append( (l,len(list(v))) )

if s[len(s)-1] == '0':
	res.append((1,0))

#for d in res:
	#print(d)

if len(res) <= 2*k + 1:
	ans = 0;
	for d in res:
		ans += d[1];

	print(ans)
	return

now = 0
ans = 0
for i in range(2*k+1):
	now += res[i][1]

ans = max(ans,now)

for i in range(2*k+1,len(res),2):
	now -= res[i-2*k-1][1]
	now -= res[i-2*k][1]

	now += res[i][1]
	now += res[i+1][1]

	ans = max(ans,now)

print(ans)



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

# count sequence man and memo the cnt in group
man_groups = []
same_cnt = 0
last_man = ""
for i in range(N):
    cur_man = S[i]
    if cur_man != last_man:
        if same_cnt > 0:
            if last_man == "0":
                same_cnt *= -1
            man_groups.append(same_cnt)
        same_cnt = 1
    else:
        same_cnt += 1
    last_man = cur_man
if same_cnt > 0:
    if last_man == "0":
        same_cnt *= -1
    man_groups.append(same_cnt)

# count max sequence man from evey pos
sum_list = []
end_pos = 2 * K if man_groups[0] > 0 else 2 * K - 1
max_man_groups_idx = len(man_groups) - 1
end_pos = min(end_pos, max_man_groups_idx)
last_max = sum(map(abs, man_groups[0: end_pos + 1]))
sum_list.append(last_max)

start_pos = 2 if man_groups[0] > 0 else 1
for i in range(start_pos, len(man_groups), 2):
    if end_pos >= max_man_groups_idx:
        break
    for j in range(2):
        idx = i - j - 1
        if idx >= 0:
            last_max -= abs(man_groups[idx])
    for j in range(2):
        end_pos += 1
        if end_pos <= max_man_groups_idx:
            last_max += abs(man_groups[end_pos])
    sum_list.append(last_max)

#print(man_groups)
#print(sum_list)
print((max(sum_list)))







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

s = []
cnt = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        s.append(cnt)
        cnt = 1
s.append(cnt)

ans = 0
if S[0] == '0':
    s = [0] + s
if S[-1] == '0':
    s = s + [0]

if 2*K + 1 > len(s):
    print(sum(s))
    return

s_cumsum = [s[0]] * len(s)
for i in range(1, len(s)):
    s_cumsum[i] = s_cumsum[i-1] + s[i]
    
for i in range(0, len(s), 2):
    if i + 2*K >= len(s):
        break
    if i < 1:
        ans = s_cumsum[i+2*K]
    ans = max(ans, s_cumsum[i+2*K]-s_cumsum[i-1])
    #ans = max(ans, sum(s[i:i+2*K+1]))

print(ans)

def run_length_compress(S):
    res = [[S[0], 1]]
    for c in S[1:]:
        if c == res[-1][0]:
            res[-1][1] += 1
        else:
            res.append([c, 1])
    return res


N, K = list(map(int, input().split()))
S = input()
cs = run_length_compress(S)
M = len(cs)

ans = 0
tot = 0
right = 0
zeros = 0
for left in range(M):
    while right < M and zeros + (cs[right][0] == "0") <= K:
        if cs[right][0] == "0":
            zeros += 1
        tot += cs[right][1]
        right += 1

    ans = max(ans, tot)

    if left == right:
        right += 1
    else:
        if cs[left][0] == "0":
            zeros -= 1
        tot -= cs[left][1]
print(ans)



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

# count sequence man and memo the cnt in group
man_groups = []
same_cnt = 0
last_man = ""
for i in range(N):
    cur_man = S[i]
    if cur_man != last_man:
        if same_cnt > 0:
            if last_man == "0":
                same_cnt *= -1
            man_groups.append(same_cnt)
        same_cnt = 1
    else:
        same_cnt += 1
    last_man = cur_man
if same_cnt > 0:
    if last_man == "0":
        same_cnt *= -1
    man_groups.append(same_cnt)

# count max from evey
sum_list = []
end_pos = 2 * K if man_groups[0] > 0 else 2 * K - 1
end_pos = min(end_pos, len(man_groups) - 1)
last_max = sum(map(abs, man_groups[0: end_pos + 1]))
sum_list.append(last_max)
for i in range(1, len(man_groups)):
    if end_pos >= len(man_groups) - 1:
        break
    last_max -= abs(man_groups[i - 1])
    if man_groups[i] > 0:
        next_end_pos = min(end_pos + 2, len(man_groups) - 1)
        man_groups_to_add = man_groups[end_pos + 1: next_end_pos + 1]
        last_max += sum(map(abs, man_groups_to_add))
        end_pos = next_end_pos
    sum_list.append(last_max)

#print(sum_list)
#print(sum_list)
print((max(sum_list)))







#ABC124 D-Handstand
n,k = map(int,input().split())
s = []
count = 0
last = 1
for i in input():
    if i=='1':
        if last==1:
            count+=1
        else:
            s.append(count)
            count=1
        last = 1
    else:
        if last==0:
            count+=1
        else:
            s.append(count)
            count=1
        last = 0
s.append(count)
if last==0:
    s.append(0)

k = min(k,len(s)//2)
ans = 0

for j in range(len(s)//2-k+1):
    if j==0:
        now = sum(s[:k*2+1])
        ans = now
    else:
        now = now-s[j*2-1]-s[j*2-2]+s[(j+k)*2]+s[(j+k)*2-1]
        ans = max(ans,now) 
print(ans)

#--初期の並びを圧縮表示,逆立ち、正立を目印--#
import sys,math,collections,itertools
input = sys.stdin.readline

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

stand = []
s_or_r = []

s_bf = '.'
cnt = 0
for i in range(N):
    if s_bf != S[i] and i != 0:
        stand.append(cnt)
        s_or_r.append(s_bf)
        cnt = 1
        s_bf=S[i]
    else:
        cnt += 1
        s_bf =S[i]
stand.append(cnt)
s_or_r.append(s_bf)


#--正立kまで許容して足す。maxが答え
if s_or_r.count('0')<=K:
    print((len(S)))
    return
#--成形==#
if s_or_r[0]=='0':
    s_or_r=['1']+s_or_r
    stand = [0]+stand
if s_or_r[-1]=='0':
    s_or_r.append('1')
    stand.append(0)
#初期条件#
tmp = sum(stand[0:2*K+1])
ans = tmp
for i in range(2,len(stand)-2*K,2):
    tmp += -(stand[i-1]+stand[i-2])+stand[i+2*K-1]+stand[i+2*K]
    ans = max(ans,tmp)
print(ans)
    


N, K = map(int, input().split())
S = input()
L = [0]
X = ['1']
pos = 0
for i in range(N):
  if S[i] != X[pos]:
    L.append(1)
    X.append(S[i])
    pos += 1
  else:
    L[pos] += 1
while pos < 2 * K + 4:
  L.append(0)
  X.append('1')
  pos += 1
L.append(0)
X.append('1')
n = len(L)
for i in range(1, n):
  L[i] += L[i-1]
M = L[2*K]
for i in range(1, n-2*K):
  if X[i] == '1':
    M = max(L[2*K+i] - L[i-1], M)
print(M)

n, k = map(int, input().split())
s = input()
ss = []
ss.append(0)
for i in range(n-1):
  a = s[i]
  if a == s[i+1]:
    continue
  ss.append(i+1)
ss.append(n)

ans = 0
for i in range(len(ss)):
  p = ss[i]
  if p == n:
    break
  if s[p] == "0":
    ans = max(ans, ss[min(2 * k + i, len(ss) - 1)] - ss[i])
  else:
    ans = max(ans, ss[min(2 * k + 1 + i, len(ss) - 1)] - ss[i])
print(ans)

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    S = SS()

    # 1の塊の長さと位置を調べる
    l = []
    if S[0] == '1':
        l.append(0)
    else:
        l.append(0)
        l.append(0)
    for i in range(N - 1):
        if S[i] == '0' and S[i+1] == '1':
            l.append(i + 1)
        elif S[i] == '1' and S[i+1] == '0':
            l.append(i + 1)
    if S[-1] == '1':
        l.append(N)
    else:
        l.append(N)
        l.append(N)
    # print(S)
    # print(l)

    # 1の塊をK+1個くっつけた場合の長さを調べる
    ans = 0
    if len(l) // 2 - 1 < K:
        ans = N
    else:
        for i in range(len(l) // 2 - K):
            ans = max(l[2*i+2*K+1] - l[2*i], ans)

    # 端の0を逆立ちさせた場合
    # if S[0] == '0':
    #     ans = max(l[2*K-1], ans)
    # if S[-1] == '0':
    #     ans = max(N - l[len(l)-2*K], ans)
    
    # 全部1だった場合(塊の間も無いし端の0もない)
    # if l == [0, N]:
    #     ans = N

    print(ans)

def __starting_point():
    resolve()

__starting_point()

from itertools import groupby
import sys

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

S = [[i, len(list(j))] for i, j in groupby(S)]

if len(S) // 2 <= K:
    if len(S) % 2 == 1 and S[-1][0] == "0":
        if len(S) == 1:
            print((sum([j for i, j in S])))
            return
            
    else:
        print((sum([j for i, j in S])))
        return

ans = 0
cnt = 0
lidx = -1
for i, j in S:
    lidx += 1
    if cnt == K and i == "0":
        break
    ans += j
    if i == "0":
        cnt += 1
sidx = 0
mans = ans
for i in range(lidx,len(S)):
    ans += S[i][1]
    if i == len(S)-1 or S[i][0] == "1":
        while True:
            ans -= S[sidx][1]
            sidx += 1
            if S[sidx][0] == "1":
                break
        mans = max(mans, ans)

print(mans)


        


N,K=map(int,input().split())
S=input()
A=[]
now=S[0]
if now=='0':
    A.append(0)
C=1
for s in S[1:]:
    if s==now:
        C+=1
    else:
        A.append(C)
        now=s
        C=1
A.append(C)
if now=='0':
    A.append(0)
B=[sum(A[:2*K+1])]
i=0
j=2*(K+1)
while j<len(A):
    b=B[-1]+sum(A[j-1:j+1])-sum(A[i:i+2])
    B.append(b)
    i+=2
    j+=2
print(max(B))


def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    # 1-0-1-0-1の配列なので間に0を含んだ数え上げ
    # なので偶数とびに1を起点に数え上げ
    left = 0
    right = 0
    tmp = 0
    # しゃくとり
    ans = 0
    for i in range(0, len(L), 2):
        nextL = i
        nextR = min(i + length, len(L))

        while nextL > left:
            tmp -= L[left]
            left += 1
        while nextR > right:
            tmp += L[right]
            right += 1

        ans = max(ans, tmp)
        
    print(ans)


def __starting_point():
    resolve()
__starting_point()

# 解説AC
# https://drken1215.hatenablog.com/entry/2019/04/14/222900
n, k = map(int, input().split())
S = list(input())

if "0" not in S:
    print(n)
    return

# 1の個数、0の個数、1の個数、、、
cnt = []

# 先頭が0なら1が0個とみなす
if S[0] == "0":
    cnt.append(0)

# 個数勘定
i = 0
while i < n:
    j = i
    while j < n and S[i] == S[j]:
        j += 1
    cnt.append(j-i)
    i = j

# 最後尾が0なら1が0個とみなす
if S[-1] == "0":
    cnt.append(0)

# cnt の累積和
cumCnt = [0]
for c in cnt:
    cumCnt.append(cumCnt[-1] + c)

# print(cnt)
# print(cumCnt)

lenCnt = len(cnt)
lenCumCnt = len(cumCnt)
ans = 0

for left in range(0, lenCumCnt, 2):
    right = min(left + 2*k+1, lenCumCnt-1)
    ans = max(ans, cumCnt[right] - cumCnt[left])
print(ans)


from itertools import accumulate


def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    acc = [0] + list(accumulate(L))
    ans = 0
    # 1-0-1-0-1の配列なので間に0を含んだ数え上げ
    # なので偶数とびに1を起点に数え上げ 
    for i in range(0, len(L) - length + 1, 2):
        ans = max(ans, acc[i + length] - acc[i])

    print(ans)


def __starting_point():
    resolve()

__starting_point()

N,K=list(map(int,input().split()))
S=input()
flag=False
cnt=[]
l=0
r=0
cnt.append([0,0])
for i in range(N):
    if flag:
        if S[i]=='0':
            r=i
            cnt.append([l,r])
            flag=False
    else:
        if S[i]=='1':
            l=i
            flag=True
if flag:
    cnt.append([l,N])
cnt.append([N,N])
ans=0
n=len(cnt)
for i in range(n):
    j=min(n-1,i+K)
    ans=max(cnt[j][1]-cnt[i][0],ans)
print(ans)


N,K=map(int,input().split())
S=input()
dp=[]
p,q=0,0
for i in S:
  if i=='1':
    if 0<q:
      dp.append(q)
    p+=1
    q=0
  else:
    if 0<p:
      dp.append(p)
    p=0
    q+=1
if 0<p:
  dp.append(p)
else:
  dp.append(q)
if S[0]=='0':
  if len(dp)<=2*K:
    print(sum(dp))
  else:
    if S[N-1]=='0':
      dp.append(0)
    dp.insert(0,0)
    ans=sum(dp[:2*K+1])
    bns=ans
    for i in range(2*K,len(dp),2):
      if i==2*K:
        continue
      bns+=dp[i]+dp[i-1]-dp[i-2*K-1]-dp[i-2*K-2]
      ans=max(ans,bns)
    print(ans)
else:
  if len(dp)<=2*K+1:
    print(sum(dp))
  else:
    if S[N-1]=='0':
      dp.append(0)
    ans=sum(dp[:2*K+1])
    bns=ans
    for i in range(2*K,len(dp),2):
      if i==2*K:
        continue
      bns+=dp[i]+dp[i-1]-dp[i-2*K-1]-dp[i-2*K-2]
      ans=max(ans,bns)
    print(ans)


from itertools import accumulate
def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    # 1-0-1-0-1の配列なので間に0を含んだ数え上げ
    # なので偶数とびに1を起点に数え上げ
    # 累積
    acc = [0] + list(accumulate(L))
    ans = 0
    for i in range(0, len(L), 2):
        left = i
        right = min(i + length, len(L))
        tmp = acc[right] - acc[left]

        ans = max(ans, tmp)

    print(ans)


def __starting_point():
    resolve()

__starting_point()

N, K = map(int, input().split())
S = input().rstrip('\n')

S += '1' if S[N-1] == '0' else '0'
sumz = [0]*(N+2)
right = 1
cnt = 1
maxlen = 0
left = 0
if K == 0:
    for i in range(N):
        if S[i] == S[i+1] and S[i] == 1:
            cnt += 1
        else:
            if maxlen < cnt:
                maxlen = cnt
            cnt = 1
else:
    cnt = 0
    while True:
        if left >= N: break
        if right <= left: right = left+1
        while (right <N) and ((cnt < K) or ((cnt == K) and ((S[right] == S[right-1]) or S[right] == '1'))):
            if (S[right] != S[right - 1]) and (S[right-1] == '0'):
                cnt += 1
            right += 1

        if not( S[right-1] == '0' and (K == 0)):
            if maxlen < right - left:
                maxlen = right - left
        #next
        while left < N and S[left] == S[left+1]:
            left += 1
        if S[left] == '0':
            cnt -= 1

        left += 1

print(maxlen)

import itertools
def s(): return input()
def I(): return map(int,input().split())

N,K = I()
S = list(s())
num = 1
cnt = 0
L = []
for i in range(N-1):
    if S[i] != S[i+1]:
        L.append(num)
        num = 0
        if S[i] == '0':
            cnt += 1
    num += 1
L.append(num)
if S[-1] == '0':
    cnt += 1
ruiseki = [0]+list(itertools.accumulate(L))
l = len(ruiseki)
if cnt <= K:
    print(N)
    return
start = 0
ans = 0
if S[0] == '0':
    start = 1
for i in range(start,l,2):
    if i+K*2+1 > l-1:
        break
    ans = max(ans,ruiseki[i+K*2+1]-ruiseki[i])
if S[0] == '0':
    ans = max(ans,ruiseki[K*2])
if S[-1] == '0':
    ans = max(ans,ruiseki[-1]-ruiseki[l-K*2-1])
print(ans)


from itertools import accumulate


def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    acc = [0] + list(accumulate(L))
    ans = 0
    for i in range(0, len(L) - length + 1, 2):
        ans = max(ans, acc[i + length] - acc[i])

    print(ans)


def __starting_point():
    resolve()
__starting_point()

import numpy as np
N, K = list(map(int, input().split()))
S = list(input())
nums = []
now = 1
cnt = 0
for s in S:
    if s == str(now):
        cnt += 1
    else:
        nums.append(cnt)
        now = 1 - now
        cnt = 1
if cnt != 0:
    nums.append(cnt)
if len(nums) % 2 == 0:
    nums.append(0)

sums = [0] + list(np.cumsum(nums))
left = 0
right = left + K * 2
maxi = 0
if N < 3:
    maxi = N
while right < len(nums):
    if sums[right+1] - sums[left] > maxi:
        maxi = sums[right+1] - sums[left]
    right += 2
    left += 2
if maxi == 0:
    maxi = sum(nums)
print(maxi)


import sys
from itertools import groupby, accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = list(map(int, readline().split()))
    S = readline().strip()

    vec = [len(list(g)) for _, g in groupby(S)]
    keys = [k for k, _ in groupby(S)]
    csum = [0]
    csum.extend(accumulate(vec))

    ans = 0
    for i in range(len(vec)):
        if keys[i] == '0':
            if i == 0:
                n = 2 * K
            else:
                continue
        else:
            n = 2 * K + 1

        if ans < csum[min(i + n, len(csum) - 1)] - csum[i]:
            ans = csum[min(i + n, len(csum) - 1)] - csum[i]

    print(ans)
    return


def __starting_point():
    main()

__starting_point()

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

on = []
off = []

acnt = 0
bcnt = 0
for i in s:
  if i == '0':
    if bcnt > 0:
      off.append(bcnt)
      bcnt = 0
    acnt += 1
  else:
    if acnt > 0:
      on.append(acnt)
      acnt = 0
    bcnt += 1
if bcnt > 0:
  off.append(bcnt)
  bcnt = 0
if acnt > 0:
  on.append(acnt)
  acnt = 0
ans = 0
if s[0] == '1':
  for i in range(len(on)-k+1):
    s = 0
    if i == 0:
      a = sum(on[i:i+k])
      b = sum(off[i:i+k+1])
    else:
      a += on[i+k-1]
      a -= on[i-1]
      if i+k <= len(off)-1:
        b += off[i+k]
      b -= off[i-1]
    # print (a,b)
    s = a+b
    ans = max(ans,s)
else:
  for i in range(len(on)-k+1):
    if i == 0:
      a = sum(on[i:i+k])
      b = sum(off[i:i+k])
    elif i == 1:
      a = sum(on[i:i+k])
      b = sum(off[i-1:i+k])
    else:
      a += on[i+k-1]
      a -= on[i-1]
      if i+k-1 <= len(off)-1:
        b += off[i+k-1]
      b -= off[i-2]
    s = a+b
    # print (a,b)
    ans = max(ans,s)
if ans == 0:
  print (n)
else:
  print (ans)


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

L = []
from itertools import groupby
for key ,value in groupby(s):
    L.append((key,len(list(value))))
#print(L)
c = []
for i in range(len(L)):
    c.append(L[i][1])
c = [0] + c

for i in range(1,len(c)):
    c[i] +=c[i-1]
#print(c)
l = 0 
r = 2*k

ans = 0
while True:
    if L[l][0] == "1":
        if l + r +1 < len(L):
            ans = max(ans,c[l+r+1] - c[l])#add 5
        else:
            ans = max(ans,c[len(L)] - c[l])
    elif L[l][0] == "0":
        if l + r < len(L):
            ans = max(ans,c[l+r] - c[l])#add 4
        else:
            ans = max(ans,c[len(L)] - c[l])
    if l == len(L)-1:
        break
    l +=1
print(ans)

n,k = map(int,input().split())
s = list(map(int,list(input())))
x = [-1]
for i in range(n-1):
    if s[i] != s[i+1]:
        x.append(i)
x.append(n-1)
t = len(x)
ans = 1

for i in range(t-1):
    if i%2 == s[0]:
        ans = max(ans,x[min(t-1,i+2*k)]-x[i])
    else:
        ans = max(ans,x[min(t-1,i+2*k+1)]-x[i])

print(ans)

n,k = map(int,input().split())
s = input()
ms = 0
ps = 0
temp = [0]
if s[0] == "0":
    temp.append(0)
for i in s:
    # print(i,ps,ms)
    if i == "0":
        ms += 1
        if ps:
            temp.append(ps)
            ps = 0
    else:
        ps += 1
        if ms:
            temp.append(ms)
            ms = 0
if ms:
    temp.append(ms)
else:
    temp.append(ps)
# print(temp)
temp.append(0)
for i in range(len(temp)-1):
    temp[i+1] += temp[i]
# print(temp)
ans = 0
if len(temp)-(2*k+1) <= 0:
    ans = temp[-1]
else:
    for i in range(0,len(temp)-(2*k+1),2):
        ans = max(ans,temp[i+2*k+1]-temp[i])
print(ans)

N, K = [int(_) for _ in input().split()]
S = input()

S = "0" + S + "0"

X = []
for i in range(N+1):
    if S[i] == "0" and S[i+1] == "1":
        st = i+1
    if S[i] == "1" and S[i+1] == "0":
        en = i
        X.append((st, en))
M = len(X)

ans = 0
for i in range(len(X) - K):
    st = X[i][0]
    en = X[i+K][1]
    ans = max(ans, en - st + 1)

if M == 0 or M + 2 < K:
    ans = N

if K <= M:
    en = X[K-1][1]
    ans = max(ans, en - 1 + 1)
    st = X[-K][0]
    ans = max(ans, N - st + 1)

print(ans)


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

lengths = []

if S.startswith('0'):
    lengths.append(0)

cont = 0
for s0, s1 in zip(S, S[1:] + 'x'):
    cont += 1
    if s0 != s1:
        lengths.append(cont)
        cont = 0

if S.endswith('0'):
    lengths.append(0)

window = 2 * K + 1

buf = sum(lengths[0:window])
ans = buf
for i in range(window, len(lengths)):
    buf += lengths[i]
    buf -= lengths[i - window]
    if i % 2 == 0:
        ans = max(ans, buf)

print(ans)


N,K=map(int,input().split())
S=input()
change=[0]
for i in range(len(S)-1):
  if S[i]!=S[i+1]:
    change.append(i+1)
change.append(N)
r=len(change)
X=[]
for i in range(r-1):
  if S[change[i]]=='0':
    a=min(i+2*K,r-1)
    X.append(change[a]-change[i])
  else:
    a=min(i+2*K+1,r-1)
    X.append(change[a]-change[i])
print(max(X))

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

nums=[]

if(s[0]=='0'):
    nums.append(0)

num=s[0]
numi=0
for i in range(n):
    if(s[i]==num):
        numi+=1
    else:
        nums.append(numi)
        numi=1
        num=s[i]
else:
    nums.append(numi)

if(s[-1]=='1'):
    nums.append(0)

#print(nums)

ans=0
zero_num=len(nums)//2
if(zero_num<=k):
    print(sum(nums))
else:
    l=2*k
    sumi=sum(nums[:l+1])
    ans=sumi
    i=0
    while(l+2<len(nums)):
        sumi+=(nums[l+1]+nums[l+2])
        l+=2
        sumi-=(nums[i]+nums[i+1])
        i+=2
        ans=max(ans,sumi)
#    print(nums[-2*k:])
    ans=max(ans,sum(nums[-2*k:]))
    print(ans)

n,k=map(int,input().split())
s=[int(i) for i in input()]
l1,l0=[],[]
b,c=1,0
for i in s:
  if b==i: c+=1
  else:
    if b: l1+=[c]
    else: l0+=[c]
    c=1
  b=i
if b:
  l1+=[c]
  l0+=[0]
else:
  l0+=[c]
S=[0]
for i,j in zip(l1,l0):
  S+=[S[-1]+i+j]
l1+=[0]
l0+=[0]
m=len(S)
if m<=k: print(n)
else:
  a=0
  for i in range(k,m):
    a=max(a,S[i]-S[i-k]+l1[i])
  print(a)

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

cl = 0
cr = 0
a = []
ans = 0
if s[0] == '1':
    ck = 0
    ans = 1
else:
    ck = 1
    a.append([0,0])
while True:
    while ck <= k and cr < n-1:
        cr += 1
        if s[cr-1] == '1' and s[cr] == '0':
            if ck < k:
                ck += 1
                a.append([cr, cr])
            else:
                break
        elif s[cr-1] == '0' and s[cr] == '1':
            a[-1][1] = cr
        ans = max(ans, cr - cl + 1)
    if cr < n-1:
        tl, tr = a.pop(0)
        cl = tr
        cr -= 1
        ck -= 1
    else:
        break
print(ans)

import itertools
N,K = map(int,input().split())
lsS = list(input())
gr = itertools.groupby(lsS)
ls = [['0',0]]
for key,group in gr:
    ls.append([key,len(list(group))])
lengr = len(ls)
lssum = []
sum1 = 0
for i in range(lengr):
    sum1 += ls[i][1]
    lssum.append([ls[i][0],sum1])
lsans = []
for i in range(1,lengr):
    if ls[i][0] == '0':
        lsans.append(lssum[min(lengr-1,i+2*K-1)][1]-lssum[i-1][1])
    elif ls[i][0] == '1':
        lsans.append(lssum[min(lengr-1,i+2*K)][1]-lssum[i-1][1])
print(max(lsans))

n, k = map(int, input().split())
s = input()
l=list()
s = s.replace("10","1,0")
s = s.replace("01","0,1")

l = [len(i) for i in s.split(",")]
r = 0
ans = 0

if s[0] == "1":
    r = min(k, len(l) - 1)
else:
    r = min(k-1, len(l) - 1)

t = l[r]

for j in range(1, k+1):
    #print(r,j,t,l[r-j],l[r+j])
    if r-j >= 0:
        #print("r-j >= 0:")
        t += l[r-j]
    if r+j < len(l):
        #print("r+j < len(l):")
        t += l[r+j]
ans = t
for i in range(r+2, len(l) ,2):
    for j in range(1, 3):
        if i-j-k >= 0:
            #print("l[i-j-k]", i-j-k, l[i-j-k])
            t -= l[i-j-k]
        if i+j+k-2 < len(l):
            #print("l[i+k+j]", i+j+k-2, l[i+j+k-2])
            t += l[i+j+k-2]
    ans = max(ans, t)
print(ans)

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

x = 1
c = [0]
for s in input():
    if int(s) == x:
        c[-1] += 1
    else:
        x ^= 1
        c.append(1)
if not x:
    c.append(0)

m = len(c)
h = min(K*2+1, m)
r = [c[0]]
for i in range(1, m):
    r.append(r[-1]+c[i])
r.append(0)

ans = 0

for i in range(0, m-h+1, 2):
    ans = max(r[i+h-1]-r[i-1], ans)

print(ans)

n,p=list(map(int,input().split()))
s=list(input())

from itertools import groupby

gr = groupby(s)

cum=[]
tmp=0
for k,v in gr:
    if k=='0':
        cum.append(tmp+len(list(v)))
        tmp=0
    elif k=='1':
        tmp+=len(list(v))


cum = list(reversed(cum))

ans = 0
cnt = 0
tmp=0
gr = groupby(s)
for k,v in gr:
    if k=='0':
        cnt+=1
        if cnt>p:
            tmp -=cum.pop()

    tmp +=len(list(v))
    ans = max(ans,tmp)


print(ans)



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

ans = 0
zeroes = 0
zeroIndices = []
ind = 0
lastZero = -1

for i in range(len(s)):
    if (s[i] == "1" and i>0 and s[i-1] == "0") or (i == len(s)-1 and s[i] == "0" and len(s)>1):
        zeroIndices.append(i-1)

        if zeroes == k:
            lastZero = zeroIndices[ind]
            ind += 1
        else:
            zeroes += 1

    if (i == len(s)-1) or (s[i] == "1" and s[i+1] == "0"):
        ans = max(ans, i-lastZero)

print(ans)

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

a = []

i = 0
while i < n:
    j = 1
    while i + j < n and s[i] == s[i + j]:
        j += 1
    a.append((s[i], j))
    i += j
if a[0][0] == '0':
    a = [('1', 0)] + a
if a[-1][0] == '1':
    a.append(('0', 0))

while len(a) < k * 2:
    a.append(('1', 0))
    a.append(('0', 0))
m = len(a)


s = [0] * (m + k * 5 + 1)
for i in range(m + k * 2):
    if i < m:
        s[i + 1] = s[i] + a[i][1]
    else:
        s[i + 1] = s[i]
ans = 0
for i in range(1, m, 2):
    ans = max(ans, s[i + k * 2] - s[i - 1])
print(ans)


n, k = map(int,input().split())
S = list(map(int, list(input())))
# 尺取り法.
## 右側の初期化.//これを不規則に動かす.
ridx = 1
## パラメータの初期化.//これでridxを制御する.
### 最初が0だった場合、最初から反転が必要.
cnt = 0 if S[0]==1 else 1
## 答えの初期化.//この最大を探す.
ans = 0
## 左側を0からn-1まで動かしていく.
for lidx in range(n):
    # 現在地が1で一つ前が0だった場合、カウントを減らす.
    if lidx>0 and S[lidx]==1 and S[lidx-1]==0:
        cnt -= 1
    # 右端がn未満なら右に一つずつ動かしていく.
    while ridx < n:
        ## もし現在地が0で、一つ前が1なら
        if S[ridx]==0 and S[ridx-1]==1:
            ### カウントがk未満ならカウントを増やし、そうでないならループを脱する.
            if cnt < k:
                cnt += 1
            else:
                break
        ridx += 1
    ans = max(ans, ridx-lidx)
print(ans)

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

ans = 0
cnt = 0
right = 1
for left in range(0, n):
    if left == 0 and s[left] == '0':
        cnt += 1

    if left > 0 and s[left] == '1' and s[left-1] == '0':
        cnt -= 1

    while right <= n - 1:
        if s[right] == '0' and s[right-1] == '1':
            if cnt < k:
                cnt += 1
            else:
                break
        right += 1

    ans = max(ans, right - left)

print(ans)


from itertools import groupby
from math import ceil

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

block = [sum(1 for _ in it) for k, it in groupby(s)]
if s[0] != '1':
    block.insert(0, 0)

m = len(block)
left, right = 0, 2*k
res = val = sum(block[left:right-1])
while right <= m:
    val += block[right-1] if right == m else block[right-1] + block[right]
    res = max(res, val)
    val -= block[left] + block[left+1]
    left += 2
    right += 2
print(res)


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

S_zero={}
S_zero_group = 0
s_befor = ''
for s_idx,s in enumerate(S):
    if s != s_befor:
        if s == '0':
            S_zero_group += 1
            S_zero[S_zero_group] = [s_idx-1]
        elif s == '1':
            if S_zero_group in S_zero.keys():
                S_zero[S_zero_group].append(s_idx)
            
    s_befor = s
    
if S[-1] == '0':
    S_zero[S_zero_group].append(N)
    
if S_zero_group <= K:
    ans_ = N
else:   
    ans_=0
    for g_s in range(1,S_zero_group-K+2):
        g_e = g_s + K - 1
#         print('====',g_s,g_e)
        s = 0
        e = N-1

        if g_s != 1:
            s = S_zero[g_s-1][1]
        if g_e != S_zero_group:
            e = S_zero[g_e+1][0]

        ans= e-s+1
        if ans > ans_:
            ans_=ans

print(ans_)

import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n, k = mi()
    s = input()
    a = [0]
    for i in range(1, n):
        if s[i]!= s[i-1]:
            a.append(i)
    a.append(n)
    ans = 0
    i, e = 0, 0
    m = len(a)
    for i in range(m):
        e = i+2*k
        if s[a[i]] == '1':
            e += 1
        e = min(e, m-1)
        ans = max(ans, a[e]-a[i])
        if e == m-1:
            break
    print(ans)
    



    
        
def __starting_point():
    main()
__starting_point()

n, k = list(map(int, input().split()))
s = list(map(int, input()))
cnt = 0
ans = 0
start = 0
for i in range(n):
    if s[i] == 0 and (i == 0 or s[i - 1] == 1):
        cnt += 1
    
    if cnt == k + 1:
        while True:
            start += 1
            if s[start - 1] == 0 and s[start] == 1:
                break
        cnt -= 1
    ans = max(ans, i - start + 1)

print(ans)


N,K=list(map(int,input().split()))
S=input()
left=0
right=0
numofturn=0
if N==1:
    print((int(S)))
else:
    if S[0]=="0":
        while(right<N):
            if S[right]=="0":
                right+=1
            else:
                break
    #print(right)
    right=max(right,1)
    while(right<N and numofturn<K):
        if S[right]=="1" and S[right-1]=="0":
            numofturn+=1
        right+=1
    while(right<N):
        if S[right]=="1":
            right+=1
        else:
            break
    #print(right)
    ans=right
    while(right<N and left<N):
        if numofturn==K:
            while(1):
                left+=1
                if left<N:
                    if S[left]!="1" or S[left-1]!="0":
                        continue
                numofturn-=1
                break
        else:
            while(1):
                right+=1
                if right<N:
                    if S[right]!="0" or S[right-1]!="1":
                        continue
                numofturn+=1
                if right==N:
                    ans=max(ans,right-left)
                else:
                    ans=max(ans,right-left)
                #print(ans,left,right)
                break
    print(ans)
    #print(left,right)


n, k = list(map(int, input().split()))
s = input()
a = [0]
for i in range(n):
    if (s[i] == "0") == (len(a) % 2 == 1):
        a.append(1)
    else:
        a[-1] += 1
t = [0]
for i in a:
    t.append(i + t[-1])
ans = 0
for i in range(len(t)):
    if i % 2 == 0:
        # print(min(i + 2 * k + 1, len(t) - 1))
        ans = max(ans, t[min(i + 2 * k + 1, len(t) - 1)] - t[i])
print(ans)



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

l = [0]
curr = '1'
for c in S:
    if c != curr:
        l.append(1)
        curr = c
    else:
        l[-1] += 1
if curr == '0':
    l.append(0)

n_group = len(l) // 2
sum_ = 0
k = min(K, n_group)
for i in range(k):
    sum_ += l[2*i] + l[2*i+1]
sum_ += l[2*k]
max_ = sum_
for i in range(k, n_group):
    sum_ -= l[2*i-2*K] + l[2*i+1-2*K]
    sum_ += l[2*i+1] + l[2*i+2]
    max_ = max(max_, sum_)
print(max_)


from itertools import groupby

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

grouped = groupby(s)

res = []

if s[0] == '0':
	res.append((1,0))

for l,v in grouped:
	res.append( (l,len(list(v))) )

if s[len(s)-1] == '0':
	res.append((1,0))

now = 0
ans = 0
for i in range(min(len(res),2*k+1)):
	now += res[i][1]

ans = max(ans,now)

for i in range(2*k+1,len(res),2):
	now -= res[i-2*k-1][1]
	now -= res[i-2*k][1]

	now += res[i][1]
	now += res[i+1][1]

	ans = max(ans,now)

print(ans)



import sys
 
N, K = map(int, sys.stdin.readline().strip().split())
S = sys.stdin.readline().strip()
 
l = x = ans = 0
for r in range(N):
    if S[r] == '0' :
        if r == 0 or S[r-1] == '1':
            x += 1
    if x > K:
        while S[l] == '1':
            l += 1
        while S[l] == '0':
            l += 1
        x -= 1
    ans = max(ans, r-l+1)
print(ans)

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

list_N = []
gr = itertools.groupby(list_S)
cnt = 0

for key, group in gr:
    list_N.append([key, len(list(group))])
    if key == "0":
        cnt += 1

if cnt <= k:
    print(n)
else:
    if list_N[0][0] == "0":
        list_N.insert(0, ["1", 0])
    if list_N[-1][0] == "0":
        list_N.append(["1", 0])

    s = 0
    for i in range(2 * k + 1):
        s += list_N[i][1]
    ans = s

    for i in range(2 * k + 2, len(list_N), 2):
        s += list_N[i][1] + list_N[i - 1][1] - list_N[i - 2 * k - 2][1] - list_N[i - 2 * k - 1][1]
        ans = max(ans, s)

    print(ans)


from itertools import groupby

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

grouped = groupby(s)

res = []

if s[0] == '0':
	res.append(0)

for l,v in grouped:
	res.append( (len(list(v))) )

if s[len(s)-1] == '0':
	res.append(0)

now = 0
ans = 0
for i in range(min(len(res),2*k+1)):
	now += res[i]

ans = max(ans,now)

for i in range(2*k+1,len(res),2):
	now -= res[i-2*k-1]
	now -= res[i-2*k]

	now += res[i]
	now += res[i+1]

	ans = max(ans,now)

print(ans)



N, K = map(int, input().split())
S = input()
L = [0]
X = ['1']
pos = 0
for i in range(N):
  if S[i] != X[pos]:
    L.append(1)
    X.append(S[i])
    pos += 1
  else:
    L[pos] += 1
while pos < 2 * K + 4:
  L.append(0)
  X.append('1')
  pos += 1
L.append(0)
X.append('1')
n = len(L)
for i in range(1, n):
  L[i] += L[i-1]
M = L[2*K]
for i in range(1, n-2*K):
  if X[i] == '1':
    M = max(L[2*K+i] - L[i-1], M)
print(M)

N, K = map(int, input().split())
S = input()
A, B = [], []
cnt_0, cnt_1 = 0, 0
for i in range(N):
    if S[i] == '0':
        cnt_0 += 1
        if cnt_1 > 0: 
            A.append(cnt_1)
        cnt_1 = 0
    else:
        cnt_1 += 1
        if cnt_0 > 0: 
            A.append(-cnt_0)
        cnt_0 = 0

if cnt_1 > 0: 
    A.append(cnt_1)
if cnt_0 > 0: 
    A.append(-cnt_0)
    
M = len(A)
minus_cnt = 0
s = 0
right = M
for i in range(M):
    if A[i] < 0 and minus_cnt == K:
        right = i
        break
    if A[i] < 0:
        minus_cnt += 1
    s += abs(A[i])

left = 0
ans = s
while right < M:
    for i in range(2):
        if not right < M: break
        s += abs(A[right])
        right += 1

    while left < M:
        if A[left] < 0: 
            s -= abs(A[left])
            left += 1
            break
        s -= abs(A[left])
        left += 1
    
    ans = max(ans, s)

print(ans)

N,K=map(int,input().split())
S='1'+input()+'1'
A=[]
now='1'
C=0
for s in S:
    if s==now:
        C+=1
    else:
        A.append(C)
        now=s
        C=1
A.append(C)
A[0]-=1
A[-1]-=1
B=[sum(A[:2*K+1])]
i=0
j=2*(K+1)
while j<len(A):
    b=B[-1]+sum(A[j-1:j+1])-sum(A[i:i+2])
    B.append(b)
    i+=2
    j+=2
print(max(B))

n,k = map(int,input().split())
s = input()
a = []
b = []
c = 0
d = "1"
for i in s:
  if d == i:
    c += 1
  else:
    if d == "1":
      b.append(c)
      d = "0"
      c = 1
    else:
      a.append(c)
      d = "1"
      c = 1
if d == "1":
  b.append(c)
else:
  a.append(c)
  b.append(0)
if k >= len(a):
  print(n)
else:
  e = sum(a[:k])+sum(b[:k+1])
  ans = e
  for i in range(len(a)-k):
    e = e-a[i]-b[i]+a[i+k]+b[i+k+1]
    ans = max(ans,e)
  print(ans)

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, k = MAP()
s = input()
count = 0
flag = 1
que = deque([0]*(2*k+1))
ans = 0
tmp = 0
for x in s:
    if x == '0':
        if flag == 1:
            que.append(count)
            tmp += count - que.popleft()
            ans = max(ans, tmp) 
            count = 0
        flag = 0
        count += 1
    else:
        if flag == 0:
            que.append(count)         
            tmp += count - que.popleft()
            count = 0
        flag = 1
        count += 1

que.append(count)
tmp += count - que.popleft()
if s[-1] == '0':
    tmp -= que.popleft()
ans = max(ans,sum(que))
print(ans)

#!/usr/bin/env python
# coding: utf-8

# In[13]:


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


# In[16]:


cnt = []
if s[0] == '0':
    cnt.append(0)
i = 0
while i < n:
    j = i
    while j < n and s[j] == s[i]:
        j += 1
    cnt.append(j- i)
    i = j
if s[-1] == '0':
    cnt.append(0)
m = len(cnt)
cs = [0] * (m+1)
for i in range(m):
    cs[i+1] = cs[i] + cnt[i]
ans = 0
for l in range(0, m+1, 2):
    r = l + 2 * k + 1
    if r > m:
        r = m
    ans = max(ans, cs[r] - cs[l])
print(ans)


# In[ ]:






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

S = S + 'E'   # 終端処理
ans = -1    # 答えの初期値（十分に小さい値）

# 立った人の連続の数
if (S[0] == '0'):
    stand = 1
else:
    stand = 0

L = 0
R = 0

# 尺取り法
while (R < N):
    # 右端を進めることが可能（立った人の連続の数がK以下）なら、右端を進める
    if (stand <= K):
        # 立った人の連続の数が増えるなら1足す
        if (S[R] == '1' and S[R + 1] == '0'):
            stand += 1
        # 答えの更新
        ans = max(ans, R - L + 1)
        R += 1
    # 進められない場合、左端と右端が同じなら両者を進める
    # 左端が右端を追い越さないための処理
    elif (L == R):
        L += 1
        R += 1
    # それ以外は左端のみを進める
    else:
        # 立った人の連続の数が減るなら1減らす
        if (S[L] == '0' and S[L + 1] == '1'):
            stand -= 1
        L += 1
        # 左端のみを進めた場合は答えを更新し得ない

print(ans)

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