#include <bits/stdc++.h>
using namespace std;
int a[2005], dl[2005], dr[2005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) ans++;
    dl[i] = ans;
  }
  ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] == 2) ans++;
    dr[i] = ans;
  }
  int mmax = 0, sum;
  for (int k = 0; k < n; k++) {
    int suml = 0, sumr = 0;
    suml = max(suml, dr[0] - dr[k]);
    for (int i = 1; i <= k; i++) {
      suml = max(suml, dl[i - 1] + dr[i] - dr[k]);
    }
    sumr = max(sumr, dl[n - 1] - dl[k]);
    for (int j = n - 2; j >= k; j--) {
      sumr = max(sumr, dr[j + 1] + dl[j] - dl[k]);
    }
    sum = suml + sumr + 1;
    mmax = max(sum, mmax);
  }
  printf("%d\n", mmax);
  return 0;
}
