#include <bits/stdc++.h>
using namespace std;
inline int R() {
  char c;
  int sign = 1, res = 0;
  while ((c = getchar()) > '9' || c < '0')
    if (c == '-') sign = -1;
  res += c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  return res * sign;
}
const int Maxn = 2e3 + 5;
int a[Maxn], n, s[Maxn], dp[Maxn][Maxn];
int main() {
  n = R();
  for (int i = 1; i <= n; i++) {
    a[i] = R() - 1;
    s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i <= n; i++) dp[i][i] = 1;
  for (int k = 1; k <= n; k++)
    for (int i = 1; i + k <= n; i++) {
      int j = k + i;
      if (a[i] == 0)
        dp[i][j] = max(dp[i + 1][j],
                       max(s[j] - s[i - 1], j - i + 1 - (s[j] - s[i - 1])));
      if (a[i] == 1)
        dp[i][j] = max(dp[i + 1][j] + 1,
                       max(s[j] - s[i - 1], j - i + 1 - (s[j] - s[i - 1])));
    }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      ans = max(dp[i][j] + i - 1 - s[i - 1] + s[n] - s[j], ans);
  printf("%d\n", ans);
}
