#include <bits/stdc++.h>
using namespace std;
int a[2009], n, pre[2009];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) pre[i]++;
  }
  for (int i = 1; i < n; i++) pre[i] += pre[i - 1];
  for (int i = 0; i < n / 2; i++) {
    swap(a[i], a[n - i - 1]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int last1 = 0, last2 = 0;
    for (int j = i; j < n; j++) {
      if (a[j] == 1)
        last1 = last1 + 1;
      else
        last2 = max(last2, last1) + 1;
      if (a[j] == 1) {
        int val = pre[n - 1 - j], val2 = (i) - (pre[n - 1] - pre[n - 1 - i]);
        ans = max(ans, val2 + last1 + val - a[j]);
      } else {
        int val = pre[n - 1 - j], val2 = (i) - (pre[n - 1] - pre[n - 1 - i]);
        ans = max(ans, val2 + last2 + val);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
