#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long mul(long long x, long long y) { return ((x % M) * (y % M) % M); }
long long binpow(long long x, long long y) {
  long long z = 1;
  while (y) {
    if (y & 1LL) z = mul(z, x);
    x = mul(x, x);
    y >>= 1LL;
  }
  return z;
}
long long inv(long long x) { return binpow(x, M - 2); }
long long divide(long long x, long long y) { return mul(x, inv(y)); }
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  vector<int> dp1(n + 1), dp2(n + 1), dp_pref(n + 1);
  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 2)
      dp2[i] = 1;
    else
      dp1[i] = 1;
    dp2[i] += dp2[i - 1];
    dp1[i] += dp1[i - 1];
  }
  for (int i = 1; i <= n; ++i) {
    int sfans = dp2[i];
    for (int j = 1; j <= i; ++j) {
      if (a[j] == 1) sfans = max(sfans, dp1[j] + dp2[i] - dp2[j]);
    }
    dp_pref[i] = sfans;
  }
  for (int i = 1; i <= n; ++i) {
    int sfans = dp_pref[i];
    for (int j = i; j >= 1; --j) {
      if (a[j] == 1) sfans = max(sfans, dp_pref[j - 1] + dp1[i] - dp1[j - 1]);
    }
    sfans += (dp2[n] - dp2[i]);
    ans = max(ans, sfans);
  }
  cout << ans << "\n";
}
