#include <bits/stdc++.h>
using namespace std;
const int mx = 2e3 + 100;
int l1[mx], l2[mx], s[mx];
int n;
int dp[mx][mx][2];
int sum(int l, int r) { return l1[l - 1] + l2[n] - l2[r]; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &s[i]);
    if (s[i] == 1)
      l1[i] = l1[i - 1] + 1, l2[i] = l2[i - 1];
    else
      l2[i] = l2[i - 1] + 1, l1[i] = l1[i - 1];
  }
  for (int l = 1; l <= n; ++l) {
    dp[l][l][s[l] & 1] = 1;
    for (int r = l + 1; r <= n; ++r) {
      if (s[r] == 2) {
        dp[l][r][0] = dp[l][r - 1][0] + 1;
        dp[l][r][1] = dp[l][r - 1][1];
      } else {
        dp[l][r][0] = dp[l][r - 1][0];
        dp[l][r][1] = max(dp[l][r - 1][1], dp[l][r - 1][0]) + 1;
      }
    }
  }
  int mxx = 0;
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      mxx = max(mxx, sum(l, r) + max(dp[l][r][0], dp[l][r][1]));
    }
  }
  printf("%d\n", mxx);
}
