#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const double PI = 3.1415926535897;
struct str {
  int k1, k2, ak1, ak2;
};
str t[10100];
int a[2020], k1[2020], k2[2020];
int n;
void make_vert(str &t, str t1, str t2) {
  t.k1 = t2.ak1;
  t.k2 = t1.ak2;
  if (t2.ak1 + t1.k1 + t1.k2 > t.k1 + t.k2) t.k1 = t2.ak1 + t1.k1, t.k2 = t1.k2;
  if (t1.ak2 + t2.k2 + t2.k1 > t.k1 + t.k2) t.k1 = t2.k1, t.k2 = t1.ak2 + t2.k2;
  t.ak1 = t1.ak1 + t2.ak1;
  t.ak2 = t1.ak2 + t2.ak2;
}
void build(int v, int tl, int tr) {
  if (tl == tr)
    t[v].k1 = t[v].ak1 = (int)(a[tl] == 1),
    t[v].k2 = t[v].ak2 = (int)(a[tl] == 2);
  else {
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    make_vert(t[v], t[v * 2], t[v * 2 + 1]);
  }
}
str findn(int v, int tl, int tr, int l, int r) {
  if (l > r) {
    str res;
    res.k1 = 0, res.k2 = 0, res.ak1 = 0, res.ak2 = 0;
    return res;
  }
  if (tl == l && tr == r) return t[v];
  int tm = (tl + tr) / 2;
  str res;
  make_vert(res, findn(v * 2, tl, tm, l, min(r, tm)),
            findn(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r));
  return res;
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  k1[0] = (int)(a[0] == 1);
  k2[0] = (int)(a[0] == 2);
  for (int i = 1; i < n; i++)
    k1[i] = k1[i - 1] + (int)(a[i] == 1), k2[i] = k2[i - 1] + (int)(a[i] == 2);
  build(1, 0, n - 1);
  int ans = 1;
  for (int l = 0; l < n; l++)
    for (int r = l; r < n; r++) {
      int cnt = 0;
      str que = findn(1, 0, n - 1, l, r);
      cnt = que.k1 + que.k2;
      cnt = max(cnt, max(que.ak1, que.ak2));
      if (l) cnt += k1[l - 1];
      cnt += k2[n - 1] - k2[r];
      ans = max(ans, cnt);
    }
  cout << ans;
  return 0;
}
