#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, a[N], cur1[N], cur2[N], ans, t[3];
inline void up(int x) { ans = max(ans, x); }
inline void upd(int pos, int val) {
  for (int i = pos; i <= 2; i |= i + 1) {
    t[i] = max(t[i], val);
  }
}
inline int get(int pos) {
  int cur = 0;
  for (int i = pos; i >= 1; i &= i + 1, i--) {
    cur = max(cur, t[i]);
  }
  return cur;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cur1[i] = cur1[i - 1];
    cur2[i] = cur2[i - 1];
    if (a[i] == 1) {
      cur1[i]++;
    } else {
      cur2[i]++;
    }
  }
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= 2; j++) {
      t[j] = 0;
    }
    for (int j = i; j >= 1; j--) {
      int x = get(a[j]);
      upd(a[j], x + 1);
      int c1 = cur1[j - 1], c2 = cur2[j - 1], c3 = cur1[n] - cur1[i],
          c4 = cur2[n] - cur2[i];
      up(c1 + t[1] + c3);
      up(c1 + t[1] + c4);
      up(c1 + t[2] + c4);
      up(c2 + t[2] + c4);
    }
  }
  cout << ans;
}
