#include <stdio.h>

#define MAXN 200100

int A[MAXN], V[MAXN], St[MAXN];
int i,st,dr,mij,sol,N,D;

inline bool Ok(int X)
{
	int nr = 1;
	V[0] = 1;
	for (i=1; i<=N; ++i){
		if (St[i] >= X && nr>0) V[i] = 1;
		else V[i] = 0;
		nr += V[i];
		if (i-X-D >= 0) nr -= V[i-X-D];
	}
	for (i=N; i>=N-D; --i)
		if (V[i]) return true;
	return false;
}

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",&A[i]);
	
	for (i=1; i<=N; ++i)
		if (A[i] == 0)
			St[i] = St[i-1] + 1;
		else
			St[i] = 0;
	
	st = 1; dr = N;
	while (st<=dr){
		mij = (st+dr) >> 1;
		if (Ok(mij)){
			sol = mij;
			st = mij+1;
		}
		else dr = mij-1;
	}

	printf("%d\n", sol);
	
	return 0;
}