#include <bits/stdc++.h>
using namespace std;
int s1[2001];
int s2[2001];
int s21[2000][2000];
int n;
int a[2000];
void Calc21() {
  for (int i = 0; i < n; i++) {
    s21[i][i] = 1;
    int t2 = 0;
    int t1 = 0;
    for (int j = i; j < n; j++) {
      if (a[j] == 2)
        ++t2;
      else
        t1 = max(t2 + 1, t1 + 1);
      s21[i][j] = max(t2, t1);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int q = i;
    while (q >= 0) s1[i + 1] += a[q--] == 1;
  }
  for (int i = 0; i < n; i++) {
    int q = i;
    while (q < n) s2[i] += a[q++] == 2;
  }
  Calc21();
  int best = s21[0][n - 1];
  for (int i = 0; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      int cur = s1[i] + s21[i][j - 1];
      cur += s2[j];
      best = max(best, cur);
    }
  cout << best;
  return 0;
}
