#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int N = (1 << 15);
const long long OO = 2ll * 1e18;
int a[2005], b[2005], c[2005];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = b[i - 1] + (a[i] == 1 ? 1 : 0);
  }
  for (int i = n; i >= 1; i--) c[i] = c[i + 1] + (a[i] == 2 ? 1 : 0);
  if (n <= 3 || b[n] == 0 || c[1] == 0) {
    cout << n;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int cn = 0, mx = 0, mxi = i + 1, mn = 0, mni = i - 1;
    for (int j = i + 1; j <= n; j++) {
      if (a[j] == 1) {
        if (mx < ++cn) {
          mx = cn;
          mxi = j;
        }
      } else
        cn--;
    }
    cn = 0;
    for (int j = i - 1; j >= 1; j--) {
      if (a[j] == 2) {
        if (mn < ++cn) {
          mn = cn;
          mni = j;
        }
      } else
        cn--;
    }
    ans = max(ans, b[mni] + c[mxi] + b[mxi] - b[i - 1] + c[mni] - c[i + 1]);
  }
  cout << ans;
  return 0;
}
