#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, k = 0;
  cin >> n;
  long long ar[n];
  for (i = 0; i < n; i++) cin >> ar[i];
  long long one[n + 1], two[n], dp[n][n];
  for (i = 0; i < n; i++) {
    one[i] = two[i] = 0;
  }
  for (i = 1; i < n; i++) {
    if (ar[i - 1] == 1)
      one[i] = one[i - 1] + 1;
    else
      one[i] = one[i - 1];
  }
  if (ar[n - 1] == 1)
    one[n] = one[n - 1] + 1;
  else
    one[n] = one[n - 1];
  for (i = n - 2; i >= 0; i--) {
    if (ar[i + 1] == 2)
      two[i] = two[i + 1] + 1;
    else
      two[i] = two[i + 1];
  }
  for (i = 0; i < n; i++) dp[i][i] = 1;
  for (j = n - 1; j > 0; j--) {
    for (i = j - 1; i >= 0; i--) {
      dp[i][j] = dp[i + 1][j];
      if (ar[i] == 2 || dp[i + 1][j] == one[j + 1] - one[i + 1])
        dp[i][j] = dp[i + 1][j] + 1;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = i; j < n; j++) {
      k = fmax(k, one[i] + two[j] + dp[i][j]);
    }
  }
  cout << k;
  return 0;
}
