#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
short dp[2020][2020][3][3], dp1[2020][2020][3][3];
int n, a[2020], b[2020], ans = -1;
void calc_up() {
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      if (a[r] == 1) {
        dp[l][r][1][1] = dp[l][r - 1][1][1] + 1;
        dp[l][r][1][2] = dp[l][r - 1][1][2];
        dp[l][r][2][2] = dp[l][r - 1][2][2];
      } else {
        dp[l][r][1][1] = dp[l][r - 1][1][1];
        dp[l][r][1][2] = max(dp[l][r - 1][1][2], dp[l][r - 1][1][1]) + 1;
        dp[l][r][2][2] = dp[l][r - 1][2][2] + 1;
      }
    }
  }
}
void calc_down() {
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      if (a[r] == 1) {
        dp1[l][r][1][1] = dp1[l][r - 1][1][1] + 1;
        dp1[l][r][2][1] = max(dp1[l][r - 1][2][1], dp1[l][r - 1][2][2]) + 1;
        dp1[l][r][2][2] = dp1[l][r - 1][2][2];
      } else {
        dp1[l][r][1][1] = dp1[l][r - 1][1][1];
        dp1[l][r][2][1] = dp1[l][r - 1][2][1];
        dp1[l][r][2][2] = dp1[l][r - 1][2][2] + 1;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  calc_up();
  calc_down();
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      int cur = max(dp[1][l - 1][1][2], dp[1][l - 1][2][2]) + dp[l][r][2][2];
      int cur1 = dp[1][l - 1][1][1] + dp1[l][r][1][1] +
                 max(dp[r + 1][n][1][2], dp[r + 1][n][2][2]);
      int cur2 = dp[1][l - 1][1][1] + dp1[l][r][2][1] + dp[r + 1][n][2][2];
      int cur3 = dp[1][l - 1][1][1] + dp1[l][r][2][2] + dp[r + 1][n][2][2];
      ans = max(ans, max(max(cur1, cur2), max(cur, cur3)));
    }
  }
  cout << ans << endl;
}
