#include <bits/stdc++.h>
using namespace std;
int s[2004];
int dp[2004][2];
int main(void) {
  int n;
  scanf("%d", &n);
  int i, j;
  for (i = 1; i <= n; i++) scanf("%d", &s[i]);
  int ans = 0;
  for (j = 1; j <= n; j++) {
    for (i = 1; i <= n; i++) dp[i][0] = dp[i][1] = 0;
    dp[1][0] = s[1] == 1 ? 1 : 0;
    dp[1][1] = s[1] == 2 ? 1 : 0;
    for (i = 2; i <= j; i++) {
      if (s[i] == 1) {
        dp[i][0] = dp[i - 1][0] + 1;
        dp[i][1] = dp[i - 1][1];
      } else {
        dp[i][0] = dp[i - 1][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
      }
    }
    dp[j + 1][0] = s[j + 1] == 1 ? 1 : 0;
    dp[j + 1][1] = s[j + 1] == 2 ? 1 : 0;
    for (i = j + 2; i <= n; i++) {
      if (s[i] == 1) {
        dp[i][0] = dp[i - 1][0] + 1;
        dp[i][1] = dp[i - 1][1];
      } else {
        dp[i][0] = dp[i - 1][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
      }
    }
    int dp1 = max(dp[j][0], dp[j][1]);
    int dp2 = max(dp[n][0], dp[n][1]);
    if (j == n) dp2 = 0;
    ans = max(ans, dp1 + dp2);
  }
  printf("%d\n", ans);
  return 0;
}
