//整个机房都是同一位神牛的膜拜者,或者两个神牛的膜拜者人数差不超过M。
#include <cstdio>
using namespace std;
int a[2501]={0},sum[3][2501]={{0}},f[2501][2501]={{0}};
int absint(int a)
{
if (a<0)
return(-a);
else
return(a);
}
int main(void)
{
freopen("orz.in","r",stdin);
freopen("orz.out","w",stdout);
int i,j,k,n,m,temp;
scanf("%d %d\n",&n,&m);
for (i=1;i<=n;i++)
{
scanf("%d\n",&a[i]);
sum[a[i]][i]=sum[a[i]][i-1]+1;
sum[3-a[i]][i]=sum[3-a[i]][i-1];
}
for (i=1;i<=n;i++)
f[i][1]=1;
for (j=2;j<=n;j++)
for (i=1;i<=n-j+1;i++)
{
if (sum[1][i+j-1]-sum[1][i-1]==0||sum[2][i+j-1]-sum[2][i-1]==0||absint((sum[1][i+j-1]-sum[1][i-1])-(sum[2][i+j-1]-sum[2][i-1]))<=m)
{
f[i][j]=1;
continue;
}
else
f[i][j]=32767;
for (k=i;k<=i+j-2;k++)
{
temp=f[i][k-i+1]+f[k+1][i+j-1-k];
if (temp<f[i][j])
f[i][j]=temp;
}
}
printf("%d\n",f[1][n]);
fclose(stdin);
fclose(stdout);
return(0);
}