#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1010];
int vis[1010];
int jiyi[1010];
int ans;
int dfs(int t,int step,int cnt,int tree)
{
if(step <= m)
{
ans = max(ans,cnt);
}
if(step > m)
{
return 0;
}
if(cnt <= jiyi[t])
{
return 0;
}
jiyi[t] = cnt;
if(t >= n-1)
{
return 0;
}
if(a[t + 1] == tree)
{
dfs(t+1,step,cnt + 1,tree);
dfs(t+1,step+1,cnt,a[t+1]);
}
else
{
dfs(t+1,step,cnt,tree);
dfs(t+1,step+1,cnt+1,a[t+1]);
}
return 0;
}
int main()
{
cin >> n >> m;
memset(jiyi,-1,sizeof jiyi);
for(int i = 0;i<n;i++)
{
cin >> a[i];
}
if(a[0] == 1)
{
dfs(0,0,1,1);
dfs(0,1,0,2);
}
else
{
dfs(0,0,0,1);
dfs(0,1,1,2);
}
cout << ans << '\n';
return 0;
}
995995