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