#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 1e3 + 50;
int n;
int a[MAXN];
int pre[MAXN], suf[MAXN];
int f[MAXN][MAXN], g[MAXN][MAXN];
int ans;
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (register int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + (a[i] == 1);
  for (register int i = n; i >= 1; --i) suf[i] = suf[i + 1] + (a[i] == 2);
  for (register int i = 1; i <= n; ++i)
    for (register int j = i; j <= n; ++j) {
      g[i][j] = g[i][j - 1] + (a[j] == 2);
      f[i][j] = max(f[i][j - 1], g[i][j - 1]) + (a[j] == 1);
    }
  for (register int i = 1; i <= n; ++i)
    for (register int j = i; j <= n; ++j)
      ans = max(ans, pre[i - 1] + suf[j + 1] + max(f[i][j], g[i][j]));
  printf("%d", ans);
  return 0;
}
