#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 50;
int a[N];
int t1[N];
int t2[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    t1[i] = t1[i - 1] + (a[i] == 1);
  }
  t2[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    t2[i] = t2[i + 1] + (a[i] == 2);
  }
  int ans = 0;
  for (int l = 1; l <= n; l++) {
    int x = t1[l - 1], xx;
    int y = 0, z = 0;
    for (int r = l; r <= n; r++) {
      xx = t2[r + 1];
      if (a[r] == 1)
        y++;
      else {
        z++;
        y = max(z, y);
      }
      ans = max(ans, x + xx + y);
    }
  }
  printf("%d\n", ans);
  return 0;
}
