#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline const T read1() {
  T m = 0;
  char k = getchar();
  while (('0' > k || k > '9') && (k != '-')) k = getchar();
  const bool f = (k == '-' ? 1 : 0);
  if (f) k = getchar();
  while ('0' <= k && k <= '9')
    m = (m << 3) + (m << 1) + (k ^ 48), k = getchar();
  return f ? -m : m;
}
int s, s1[2002], s2[2002];
bool a[2002];
int main() {
  s = read1<int>();
  for (int i = 1; i <= s; ++i) s1[i] = s1[i - 1] + (a[i] = read1<int>() & 1);
  for (int i = s; i; --i) s2[i] = s2[i + 1] + !a[i];
  int ans = 0;
  for (int i = 1; i <= s + 1; ++i) {
    int M1 = 0, M2 = 0;
    for (int j = 1; j <= i; ++j) M1 = max(M1, s1[j - 1] - s2[i] + s2[j]);
    for (int j = i; j <= s + 1; ++j)
      M2 = max(M2, s2[j] + s1[j - 1] - s1[i - 1]);
    ans = max(ans, M1 + M2);
  }
  printf("%d", ans);
  return 0;
}
