# include <stdio.h>
int d[200010],i,n,x,y,h,l,nr,max,s,mx,j,pz;
int main ()
{
	freopen ("obstacole.in","r",stdin);
	freopen ("obstacole.out","w",stdout);
	scanf ("%d %d",&n,&h);
	l=0;
	scanf ("%d",&y);
	nr=1;
	for (i=2; i<=n; i++)
	{
		scanf ("%d",&x);
		if (x==y) nr++;
		else 
		{
			l++;
			d[l]=nr;
			if (y==1) 
			{
				if (d[l]>h)
				{
					printf ("0\n");
					return 0;
				}
				d[l]*=-1;
			}
			y=x;
			nr=1;
		}
	}
	l++;
	d[l]=nr;
	if (y==1) d[l]*=-1;
	pz=0;
	max=n;
	s=0;
	while (pz<=l)
	{
		s=0;
		mx=0;
		i=pz;
		while (s<=h)
		{
			if (i<l)
			{
				i++;
				if (d[i]>0)
				{
					if (d[i]>=mx)
					{
						mx=d[i];
						j=i;
					}
					s+=d[i];
				}
				else s-=d[i];
			}
			else 
			{
				s=h+1;
				mx=max;
				j=l+1;
			}
		}
		if (mx<max) max=mx;
		pz=j;
	}
	printf ("%d\n",max);
	return 0;
}