#include<stdio.h>
#include<string.h>

#define maxim(a,b) (a>b ? a : b)
#define NMAX 200005

int n,D,sol;
int v[NMAX];
int p[NMAX];

int merge(int val)
{
	int i,last=0;
	for(i=1;i<=n;i++)
		if(p[i]>=val && last>=i-val-D)
			last=i;
	return n-last<=D;
}

int main ()
{
	int i,st,dr=0,mij;
	
	freopen("obstacole.in","r",stdin);
	freopen("obstacole.out","w",stdout);
	scanf("%d%d",&n,&D);
	for(i=1;i<=n;i++)
		scanf("%d",&v[i]);
	memset(p,0,sizeof(p));
	for(i=1;i<=n;i++)
		if(!v[i])
			p[i]=p[i-1]+1;

	st=1;sol=0;dr=n;
	while(st<=dr)		
	{
		mij=(st+dr)/2;
		if(merge(mij))
		{
			sol=mij;
			st=mij+1;
		}
		else
			dr=mij-1;
	}
	printf("%d\n",sol);
	return 0;
}






