#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 5e3 + 3, M = 1e5 + 3, BIG = (long long)1e18 + 3,
                MOD = 1e9 + 7, P = 'z' - 'a' + 1, K = 4;
const double PI = 3.14159265359;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, ans = 0;
  cin >> n;
  vector<int> a(n + 2), pref1(n + 2), pref2(n + 2);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pref1[i] = pref1[i - 1] + (a[i] == 1);
    pref2[i] = pref2[i - 1] + (a[i] == 2);
  }
  for (int i = 0; i <= n; ++i) ans == max(ans, pref1[i] + pref2[n] - pref2[i]);
  for (int L = 1; L <= n; ++L) {
    int ans_now1 = 0, ans_now2 = 0;
    for (int R = L; R <= n; ++R) {
      if (a[R] == 2)
        ++ans_now2;
      else
        ans_now1 = max(ans_now2, ans_now1) + 1;
      ans = max(ans,
                pref1[L - 1] + max(ans_now2, ans_now1) + pref2[n] - pref2[R]);
    }
  }
  cout << ans;
  return 0;
}
