#include <bits/stdc++.h>
using namespace std;
long long poww(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}
const long long MAXN = 1e6 + 10;
const long long INF = 8e18;
const long long MOD = 1e9 + 7;
long long mx1[MAXN] = {0}, dp[MAXN][4] = {0};
vector<long long> A;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  A.push_back(0);
  vector<pair<long long, long long> > v;
  long long cnt = 0, prv = 0;
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (x != prv) {
      if (cnt > 0) {
        v.push_back({cnt, prv});
        cnt = 0;
      }
      prv = x;
    }
    cnt++;
    A.push_back(x);
  }
  v.push_back({cnt, prv});
  cnt = 0;
  n = v.size();
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (v[i].second == 1 && v[j].second == 2)
        ans = max(ans, v[i].first + v[j].first);
    }
    if (i > 0) mx1[i] = mx1[i - 1];
    if (v[i].second == 1) mx1[i] = max(mx1[i], v[i].first);
  }
  for (int i = 1; i < A.size(); i++) {
    long long tcnt = 0, ocnt = 0;
    for (int k = 0; k <= i; k++) {
      if (A[k] == 1) ocnt++;
      if (A[k] == 2) tcnt++;
    }
    for (int j = 0; j <= i; j++) {
      if (A[j] == 1) ocnt--;
      if (A[j] == 2) tcnt--;
      dp[i][0] = max(dp[i][0], ocnt);
      dp[i][1] = max(dp[i][1], dp[j][0] + tcnt);
      dp[i][2] = max(dp[i][2], dp[j][1] + ocnt);
      dp[i][3] = max(dp[i][3], dp[j][2] + tcnt);
      ans = max(ans, dp[i][3]);
    }
  }
  cout << ans << '\n';
  return 0;
}
