#include <bits/stdc++.h>
using namespace std;
const int N = 2004;
int sum1[N], sum2[N], a[N];
int tree[4 * N];
void build(int nd, int l, int r) {
  if (l == r) {
    tree[nd] = sum1[l] + sum2[l + 1];
    return;
  }
  int mid = (l + r) / 2;
  build(2 * nd, l, mid);
  build(2 * nd + 1, mid + 1, r);
  tree[nd] = min(tree[2 * nd], tree[2 * nd + 1]);
}
int query(int nd, int l, int r, int ql, int qr) {
  if (l > r || ql > r || qr < l) return 100000000;
  if (ql <= l && qr >= r) return tree[nd];
  int mid = (l + r) / 2;
  int q1 = query(2 * nd, l, mid, ql, qr);
  int q2 = query(2 * nd + 1, mid + 1, r, ql, qr);
  return min(q1, q2);
}
int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n + 1; i++) sum1[i] = sum1[i - 1] + ((a[i] == 1) ? 1 : 0);
  for (i = n; i >= 0; i--) sum2[i] = sum2[i + 1] + ((a[i] == 2) ? 1 : 0);
  build(1, 1, n);
  int mx = 0;
  for (i = 0; i <= n; i++) mx = max(mx, sum1[i] + sum2[i + 1]);
  for (i = 0; i <= n; i++) {
    for (j = i + 3; j <= n + 1; j++) {
      int ans = sum1[i] + sum2[j] - query(1, 1, n, i + 1, j - 1) + sum1[j - 1] +
                sum2[i + 1];
      mx = max(ans, mx);
    }
  }
  printf("%d\n", mx);
  return 0;
}
