# include <cstdio>
# define NMAX 20022
# define INF 1000000111

using namespace std;

int n,d,l;
int unu[NMAX],zero[NMAX],a[NMAX];
int st,mij,dr;
int uma,zma,u,z;

int verifica (int x);

int main ()
{
	int i;
	freopen ("obstacole.in","r",stdin);
	freopen ("obstacole.out","w",stdout);
	scanf ("%d%d",&n,&d);
	u=0;z=0; uma=0; zma=0;
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)
		{
			if (zma<z)
				zma=z;
			z=0;
			u++;
		}
		else
		{
			if (uma<u)
				uma=u;
			u=0;
			z++;
		}
	}
	if (uma>d)
		printf("0\n");
	else
	{
		// generare unu si 0
		for (i=n;i>0;i--)
		{
			if (a[i]==0)
			{
				unu[i]=0;
				zero[i]=zero[i+1]+1;
			}
			else
			{
				unu[i]=unu[i+1]+1;
				zero[i]=0;
			}
		}
		zero[0]=1;
		zero[n+1]=INF;
		st=0; dr=zma;
		while (st<dr)
		{
			mij=(st+dr+1)/2;
			if (verifica(mij))
				st=mij;
			else dr=mij-1;
		}
		printf("%d\n",st);
	}
	return 0;
}

int verifica (int x)
{
	int i,gasit;
	i=0;
	while (i<n)
	{
		// merg pe secventa de 0 cat se poate
		i+=zero[i];
		// sar pana la primul  spatiu de picior
		if (i+d>n)
			return 1;
		gasit=i;
		while (zero[i+unu[i]]<x)
		{
			i+=unu[i];
			i+=zero[i];
		}
		i+=unu[i];
		if (i-gasit-1>d)
			return 0;
	}
	return 1;
}
