#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<long long> pref(n + 2, 0), suf(n + 2, 0);
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + (a[i] == 1);
  }
  for (int i = n; i >= 1; i--) suf[i] = suf[i + 1] + (a[i] == 2);
  long long res = 0;
  for (int i = 0; i <= n; i++) {
    res = max(res, pref[i] + suf[i + 1]);
  }
  for (int l = 1; l <= n; l++) {
    long long cnt1 = 0, cnt2 = 0, t = 0;
    for (int r = l; r <= n; r++) {
      if (a[r] == 1)
        cnt1++;
      else
        cnt2++;
      if (cnt2 >= cnt1) {
        t += cnt2;
        cnt1 = 0;
        cnt2 = 0;
      }
      res = max(res, pref[l - 1] + suf[r + 1] + cnt1 + t);
    }
  }
  cout << res;
  return 0;
}
