#include <cstdio>
#include <cstdlib>

const int N = 200005;

int n, d, a[N], zd[N];

void read() {
	scanf("%d%d", &n, &d);
	
	for (int i = 1; i <= n; ++ i)
		scanf("%d", &a[i]);
}

void verif() {
	int mc = - 1, l = 0;
	
	for (int i = 1; i <= n; ++ i) {
		if (a[i] == 1)
			++ l;
		else 
			l = 0;
		
		if (l > mc)
			mc = l;
	}
	
	if (mc > d) {
		printf("0");
		exit(0);
	}
}

bool drum (int l) {
	int st = 0, newp;
	
	while (st + d + 1<= n) {
		newp = st + d + 1;
		
		while (newp >= 0 && zd[newp] < l && newp >= st - l + 2)
			-- newp;
		
		if (newp < st - l + 2 || newp < 0)
			return false;
		
		st = newp + l - 1;
	}
	
	return true;
}

int cb() {
	int i = 0, pas = 1 << 18;
	
	for (i = 0; pas; pas >>= 1)
		if (drum(i + pas))
			i += pas;
	
	return i;
}

void pregen() {
	for (int i = n; i >= 1; -- i)
		if (a[i] == 0)
			zd[i] = zd[i + 1] + 1;
}

int main() {
	freopen("obstacole.in", "r", stdin);
	freopen("obstacole.out", "w", stdout);
	
	read();
	verif();
	pregen();
	printf("%d", cb());
	
	return 0;
}
