#include <bits/stdc++.h>
using namespace std;
int a[2005];
int leftone[2005];
int lefttwo[2005];
int dp[2005][2005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    leftone[i] = leftone[i - 1];
    if (a[i] == 1) leftone[i]++;
  }
  for (int i = 1; i <= n; i++) {
    lefttwo[i] = lefttwo[i - 1];
    if (a[i] == 2) lefttwo[i]++;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j + i - 1 <= n; j++) {
      if (a[j] == 1)
        dp[j][i + j - 1] =
            max(dp[j + 1][i + j - 1], leftone[i + j - 1] - leftone[j - 1]);
      else
        dp[j][i + j - 1] = dp[j + 1][i + j - 1] + 1;
    }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      ans = max(ans, leftone[i - 1] + lefttwo[n] + dp[i][j] - lefttwo[j]);
  cout << ans << endl;
}
