#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> arr(n + 1);
  for (int i = 1; i <= n; i++) cin >> arr[i], arr[i]--;
  vector<array<int, 2>> inc(n + 2), dec(n + 2);
  for (int i = 1; i <= n; i++) {
    inc[i][arr[i]] = inc[i - 1][arr[i]] + 1;
    inc[i][arr[i] ^ 1] = inc[i - 1][arr[i] ^ 1];
    if (arr[i]) {
      inc[i][1] = max(inc[i][1], inc[i - 1][0] + 1);
    }
  }
  for (int i = n; i; i--) {
    dec[i][arr[i]] = dec[i + 1][arr[i]] + 1;
    dec[i][arr[i] ^ 1] = dec[i + 1][arr[i] ^ 1];
    if (!arr[i]) {
      dec[i][0] = max(dec[i][0], dec[i + 1][1] + 1);
    }
  }
  int ans = max(inc[n][0], inc[n][1]);
  for (int i = 1; i <= n; i++) {
    int owo[2][2] = {0, 0};
    for (int j = i; j <= n; j++) {
      swap(i, j);
      owo[i & 1][arr[i]] = owo[~i & 1][arr[i]] + 1;
      owo[i & 1][arr[i] ^ 1] = owo[~i & 1][arr[i] ^ 1];
      if (!arr[i]) {
        owo[i & 1][0] = max(owo[i & 1][0], owo[~i & 1][1] + 1);
      }
      swap(i, j);
      ans = max(ans, inc[i - 1][0] + owo[j & 1][0] + dec[j + 1][1]);
    }
  }
  cout << ans << '\n';
}
