#include<stdio.h>
int f[1010][35]={0},a[1010][3]={0};
int max(int x,int y){return x>y?x:y;}
int _521()
{
freopen("bcatch.in","r",stdin);
freopen("bcatch.out","w",stdout);
int n,m,k,i,j,ans=0;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
scanf("%d",&j),a[i][j]=1;
for(i=1;i<=n;i++)
for(j=0;j<=m;j++)
f[i][j]=max(f[i-1][j],f[i-1][j-1])+a[i][(j&1)?2:1],
ans=max(f[i][j],ans);
printf("%d\n",ans);
return 0;
}
int _520=_521();
int main(){;}