#include <stdio.h>
#include <algorithm>
#define NMAX 200001
#define LMAX 100005
#define x first
#define y second

using namespace std;

int N, D, i, x, Max0, Max1, Ct[2], Inc[2], NrInt, Max;
bool A[NMAX];
pair< int, int > Intervale[LMAX];

inline bool ok( int Pas )
{
	int start = 0, ct = 1;
	
	for( ; ct < NrInt ; )
	{
		while( Intervale[ct].y - Intervale[ct].x + 1 < Pas && Intervale[ct+1].x - Intervale[start].y - 1 <= D 
			&& ct < NrInt-1 )
			ct++;
		
		if( Intervale[ct].y - Intervale[ct].x + 1 < Pas ) return false;
		start = ct++;
	}

	return true;
}

inline void BS( int L, int R )
{
	if( L <= R )
	{
		int M = (L+R)/2;
		
		if( ok( M ) )
		{
			if( M > Max ) Max = M;
			BS( M+1, R );
		}
		else BS( L, M-1 );
	}
}

int main()
{
	freopen("obstacole.in", "r", stdin);
	freopen("obstacole.out", "w", stdout);
	
	scanf("%d %d", &N, &D);
	Max0 = Max1 = -2000000;
	Ct[1] = Ct[0] = 0;
	
	scanf("%d", &x);
	A[1] = (bool)(x);
	++Ct[x];
	
	Inc[x] = 1;
	Intervale[0] = make_pair( 0, 0 );
	NrInt = 1;
	
	for( i=2; i<=N; i++ )
	{
		scanf("%d", &x);
		A[i] = (bool)(x);
		++Ct[x];
		
		if( (A[i]^A[i-1]) )
		{
			if( A[i-1] )
			{
				if( Ct[1] > Max1 ) Max1 = Ct[1];
				Ct[1] = 0;
				Ct[0] = 1;
				Inc[0] = i;
			}
			else
			{
				if( Ct[0] > Max0 ) Max0 = Ct[0];
				Intervale[NrInt++] = make_pair( Inc[0], Inc[0]+Ct[0]-1 );
				
				Ct[0] = 0;
				Ct[1] = 1;
				Inc[1] = i;
			}
		}
	}
	
	if( Max1 > D )
	{
		printf("0\n");
		return 0;
	}
	
	Max = -2000000000;
	BS( 1, Max0 );
	printf("%d\n", Max);
	
	return 0;
}
