#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 10;
int sum[maxn][3], a[maxn], n, f[maxn][3], ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i][1] = sum[i - 1][1];
    sum[i][2] = sum[i - 1][2];
    sum[i][a[i]]++;
  }
  for (int l = 1; l <= n; l++) {
    f[l - 1][1] = f[l - 1][2] = 0;
    for (int r = l; r <= n; r++) {
      f[r][1] = f[r - 1][1];
      f[r][2] = f[r - 1][2];
      if (a[r] == 2)
        f[r][2]++;
      else
        f[r][1]++;
      f[r][1] = max(f[r][1], f[r][2]);
      int len = max(f[r][1], f[r][2]);
      ans = max(ans, sum[l - 1][1] + len + sum[n][2] - sum[r][2]);
    }
  }
  f[0][1] = f[0][2] = 0;
  for (int i = 1; i <= n; i++) {
    f[i][1] = f[i - 1][1];
    f[i][2] = f[i - 1][2];
    if (a[i] == 1)
      f[i][1]++;
    else
      f[i][2]++;
    f[i][2] = max(f[i][2], f[i][1]);
  }
  ans = max(ans, max(f[n][1], f[n][2]));
  printf("%d\n", ans);
}
