#include <bits/stdc++.h>
int dp[2010][2010];
int a[2010];
int b[3][2010];
int main() {
  int n;
  scanf("%d", &n);
  for (int k = 1; k <= n; k++) scanf("%d", &a[k]);
  for (int k = 1; k <= n; k++) {
    b[1][k] = b[1][k - 1];
    b[2][k] = b[2][k - 1];
    b[a[k]][k]++;
  }
  int p, q;
  p = q = 0;
  for (int k = 1; k <= n; k++) {
    if (a[k] == 1) {
      if (q == 0) {
        p++;
      } else {
        p++;
        q--;
      }
    } else {
      q++;
    }
  }
  int ans = p + q;
  for (int k = 1; k <= n; k++) {
    p = q = 0;
    for (int i = k; i <= n; i++) {
      if (a[i] == 2) {
        if (q == 0) {
          p++;
        } else {
          p++;
          q--;
        }
      } else {
        q++;
      }
      int s = p + q + (b[1][k - 1] - b[1][0]) + (b[2][n] - b[2][i]);
      if (s > ans) ans = s;
    }
  }
  printf("%d", ans);
}
