#include <bits/stdc++.h>
using namespace std;
int n;
int s[2010];
int a[2010][2010], b[2010][2010], c[2010][2010];
int len[2010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", s + i);
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) a[i][j] = a[i][j - 1] + (s[j] == 1);
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) b[i][j] = b[i][j - 1] + (s[j] == 2);
  for (int i = 1; i <= n + 1; ++i) len[i] = a[1][i - 1] + b[i][n];
  for (int l = 1; l <= n; ++l)
    for (int r = l; r <= n; ++r) {
      if (s[r] == 1) {
        c[l][r] = max(c[l][r - 1] + 1, max(b[l][r - 1] + 1, a[l][r]));
      } else {
        c[l][r] = max(c[l][r - 1], b[l][r]);
      }
    }
  int ans = 0;
  for (int i = 1; i <= n + 1; ++i) ans = max(ans, len[i]);
  for (int l = 1; l <= n; ++l)
    for (int r = l; r <= n; ++r)
      ans = max(ans, a[1][l - 1] + c[l][r] + b[r + 1][n]);
  printf("%d\n", ans);
  return 0;
}
