#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int f = 0;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  if (f) x = -x;
}
int a[2005], n, s1[2005], s2[2005], ans;
int main() {
  int i, j, k;
  read(n);
  for (i = 1; i <= n; i++) {
    read(a[i]);
    s1[i] = s1[i - 1] + (a[i] == 1);
    s2[i] = s2[i - 1] + (a[i] == 2);
  }
  for (i = 1; i <= n; i++) {
    int sa = 0, sb = 0;
    for (j = i; j >= 0; j--) sa = max(sa, s1[j] + s2[i] - s2[j]);
    for (j = i; j <= n; j++) sb = max(sb, s1[j] - s1[i] + s2[n] - s2[j]);
    ans = max(ans, sa + sb);
  }
  printf("%d", ans);
}
