#include <cstdio>
#include <cstring>

#define MAX 200005

struct vector
{
	int cnt;
	char x;
}v[MAX];

char A[MAX];

int main()
{
	int i,N,D,x,cnt,size,sol;
	
	freopen("obstacole.in","r",stdin);
	
	scanf("%d%d",&N,&D);
	for(i=1;i<=N;i++) scanf("%d",&A[i]);
	
	memset(v,0,sizeof(v));
	cnt=0;
	x=1;
	size=0;
	for(i=1;i<=N;i++)
		if(A[i]==x) cnt++;
		else
		{
			v[++size].x=x;
			v[size].cnt=cnt;
			x=1-x;
			cnt=1;
		}
	v[++size].x=x;
	v[size].cnt=cnt;
	
	freopen("obstacole.out","w",stdout);
	
	for(i=1;i<=size;i++)
		if(v[i].x)
			if(v[i].cnt>D)
			{
				printf("0\n");
				return 0;
			}
			
	sol=N;
	for(i=1;i<=size;i++)
		if(v[i].x==0)
			if(v[i].cnt<sol) sol=v[i].cnt;
		
	printf("%d\n",sol);
	
	return 0;
}
