#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:210886422")
using namespace std;
const int MOD = 998244353;
const int INF = 1000000001;
const long double EPS = 1e-13;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
long long nextLong(long long l, long long r) {
  uniform_int_distribution<long long> foo(l, r);
  return foo(rnd);
}
double nextDouble(double l, double r) {
  uniform_real_distribution<double> foo(l, r);
  return foo(rnd);
}
double workTime() { return double(clock()) / CLOCKS_PER_SEC; }
void myReturn(int code = 0) { exit(code); }
int n, a[2010], cnt1[2010], cnt2[2010];
int pref[2010], suff[2010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] == 1) {
      ++cnt1[i];
    } else {
      ++cnt2[i];
    }
  }
  for (int i = 2; i <= n + 1; ++i) {
    cnt1[i] += cnt1[i - 1];
    cnt2[i] += cnt2[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      pref[i] = max(pref[i], cnt1[j] + cnt2[i] - cnt2[j]);
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int j = n; j >= i - 1; --j) {
      suff[i] = max(suff[i], cnt2[n] - cnt2[j] + cnt1[j] - cnt1[i - 1]);
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans = max(ans, pref[i] + suff[i + 1]);
  }
  cout << ans << endl;
  myReturn();
}
