#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int gi() {
  int x = 0, w = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') w = 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return w ? x : -x;
}
int n, a[N], s1[N][N], s2[N][N], dp[5][N];
int main() {
  n = gi();
  for (int i = 1; i <= n; ++i) a[i] = gi();
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) {
      s1[i][j] = s1[i][j - 1] + (a[j] == 1);
      s2[i][j] = s2[i][j - 1] + (a[j] == 2);
    }
  for (int i = 1; i <= 4; ++i)
    for (int j = 1; j <= n; ++j)
      for (int k = 0; k <= j; ++k)
        if (i & 1)
          dp[i][j] = max(dp[i][j], dp[i - 1][k] + s1[k + 1][j]);
        else
          dp[i][j] = max(dp[i][j], dp[i - 1][k] + s2[k + 1][j]);
  printf("%d\n", dp[4][n]);
  return 0;
}
