#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
int a[maxn];
int luo[maxn][maxn];
int pre2[maxn], pre1[maxn], tail2[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  pre2[0] = 0, pre1[0] = 0;
  for (int i = 1; i <= n; i++) {
    pre1[i] = pre1[i - 1];
    pre2[i] = pre2[i - 1];
    if (a[i] == 1)
      pre1[i]++;
    else
      pre2[i]++;
  }
  tail2[n + 1] = 0;
  for (int i = n; i > 0; i--) {
    tail2[i] = tail2[i + 1];
    if (a[i] == 2) tail2[i]++;
  }
  for (int i = 1; i <= n; i++) {
    luo[i][i] = 1;
    for (int j = i + 1; j <= n; j++) {
      if (a[j] == 1)
        luo[i][j] = luo[i][j - 1] + 1;
      else
        luo[i][j] = max(pre2[j] - pre2[i - 1], luo[i][j - 1]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      ans = max(ans, pre1[i - 1] + tail2[j + 1] + luo[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
