#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 505;
int n, k;
vector v(maxn), rev(maxn);
int one[maxn], two[maxn];
int query(int i, int j, char c) {
if(i == 0) {
if(c == '1') {
return one[j];
}
else {
return two[j];
}
}
if(i > j) {
return 0;
}
if(c == '1') {
return one[j] - one[i - 1];
}
return two[j] - two[i - 1];
}
int main() {
ios_base::sync_with_stdio(false);
// ifstream cin("in.txt");
cin >> n >> k;
int o = 0, t = 0;
for(int i = 0; i < n; i++) {
cin >> v[i];
if(v[i] == 1) {
o++;
}
else {
t++;
}
one[i] = o;
two[i] = t;
}
int ret = 0;
if(k <= 2) {
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
for(int x = j; x > i; x--) {
ret = max(ret, query(0, i - 1, '1') + query(x, j, '1') + query(i, x - 1, '2') + query(j + 1, n - 1, '2'));
}
}
}
cout << ret << endl;
return 0;
}