#include <cstdio>
#include <algorithm>

using namespace std;

#define maxn 200010

int n, d, i, j, k, sol, cand, pt, c1, c2;
int sp[maxn], sd[maxn];
char s[maxn*2+10];

int main()
{
    freopen("obstacole.in", "r", stdin);
    freopen("obstacole.out", "w", stdout);

    scanf("%d%d\n", &n, &d);

    fgets(s+2, maxn*2, stdin);
    for(int i=1; i<=n; ++i)
        sp[i]+=sp[i-1]+s[i*2]-'0';

    sp[n+1]=sp[n];

    for(pt=1; pt*2<=n; pt*=2);
    for(; pt>0; pt/=2)
    {
        if(sol+pt>n)
            continue;
        cand=sol+pt;
        for(int i=1; i<=n+1; ++i)
        {
            c1=c2=0;
            sd[i]=sd[i-1];

            if(sp[i]!=sp[i-1])
                continue;

            if(i+cand-1<=n)
            {
                if(sp[i+cand-1]==sp[i-1])
                    c1=1;
            }
            if(i==n+1)
                c1=1;
            if(i-d-1<=0)
                c2=1;
            else
            if(sd[i-1]!=sd[max(i-d-cand-1, 0)])
                c2=1;

            if(c1==1 && c2==1)
                ++sd[i];
        }
        if(sd[n+1]!=sd[n])
            sol=cand;
    }

    printf("%d\n", sol);
    return 0;
}

