#include <fstream>
#define NMax 200010
#define INF 0x3f3f3f3f
using namespace std;

const char IN[]="obstacole.in",OUT[]="obstacole.out";

ifstream fin(IN);
ofstream fout(OUT);

int N,D;
bool a[NMax];
int c[NMax];

bool test(int L)
{
	int i,last=0-L;
	for (i=0;i<=N && a[i]==0;++i) ++last;
	for (;i<=N && i-last<=D+L;++i)
		if (c[i]>=L)
			last=i;
	return i==N+1;
}

int search(int L)
{
	int step,i;
	for (step=1;step<=L;step<<=1);
	for (i=0;step;step>>=1)
		if (i+step<=L && test(i+step))
			i+=step;
	return i;
}

void init()
{
	int i;
	c[N]=INF;
	for (i=N-1;i>=0;--i)
		if (!a[i])
			c[i]=c[i+1]+1;
}

int main()
{
	int i,x;
	fin>>N>>D;
	for (i=0;i<N;++i)
		fin>>x,
		a[i]=x==1;
	
	init();

	fout<<search(N)<<"\n";
	return 0;
}
