#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
int a[maxn];
int cnt1[maxn][maxn];
int cnt2[maxn][maxn];
int dp[maxn][maxn][3];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    cnt1[i][i] = (a[i] == 1);
    cnt2[i][i] = (a[i] == 2);
    dp[i][i][a[i]] = 1;
  }
  for (int len = 2; len <= n; ++len)
    for (int l = 1; l + len - 1 <= n; ++l) {
      cnt1[l][l + len - 1] = cnt1[l][l + len - 2] + (a[l + len - 1] == 1);
      cnt2[l][l + len - 1] = cnt2[l][l + len - 2] + (a[l + len - 1] == 2);
      dp[l][l + len - 1][1] = dp[l][l + len - 2][1];
      dp[l][l + len - 1][2] = dp[l][l + len - 2][2];
      if (a[l + len - 1] == 1) {
        dp[l][l + len - 1][1] =
            max({dp[l][l + len - 1][1], dp[l][l + len - 2][1] + 1,
                 dp[l][l + len - 2][2] + 1});
      } else {
        dp[l][l + len - 1][2] =
            max(dp[l][l + len - 1][2], dp[l][l + len - 2][2] + 1);
      }
    }
  int ans = max(cnt1[1][n], cnt2[1][n]);
  for (int l = 1; l <= n; ++l)
    for (int r = l; r <= n; ++r) {
      int on_left1 = (l == 1) ? 0 : cnt1[1][l - 1];
      int on_left2 = (l == 1) ? 0 : cnt2[1][l - 1];
      int on_right1 = (r == n) ? 0 : cnt1[r + 1][n];
      int on_right2 = (r == n) ? 0 : cnt2[r + 1][n];
      ans = max(ans, on_left1 + dp[l][r][1] + on_right2);
      ans = max(ans, on_left1 + dp[l][r][2] + on_right2);
    }
  cout << ans;
}
