#include <cstdio>
using namespace std;
int a[2501]={0},sum[3][2501]={{0}},f[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,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];
}
f[1]=1;
for (i=2;i<=n;i++)
{
if (sum[1][i]==0||sum[2][i]==0||absint(sum[1][i]-sum[2][i])<=m)
{
f[i]=1;
continue;
}
else
f[i]=f[i-1]+1;
for (j=2;j<=i-1;j++)
if (sum[1][i]-sum[1][j-1]==0||sum[2][i]-sum[2][j-1]==0||absint((sum[1][i]-sum[1][j-1])-(sum[2][i]-sum[2][j-1]))<=m)
{
temp=f[j-1]+1;
if (temp<f[i])
f[i]=temp;
}
}
printf("%d\n",f[n]);
fclose(stdin);
fclose(stdout);
return(0);
}