#include<stdio.h>
int n,i,j,d,v[200001],m,dr,st,min=8000000,ok,k,ok1;
int main()
{
	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]);
	for(i=1;i<=n;i++)
	{
		if(v[i]==0)
			st++;
		else
		{
		if(st<min&&st!=0)
			min=st;
		st=0;
		}
	}
	for(i=1;i<=n;i++)
	{
		if(v[i]==1)
			dr++;
		else
		{
			if(dr>m)
				m=dr;
			dr=0;
		}
	}
	if(m>d)min=0;
	printf("%d",min);
	return 0;
}
				
	
