#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int a[N];
int num1[N], num2[N];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    num1[i] = num1[i - 1];
    num2[i] = num2[i - 1];
    a[i] == 1 ? num1[i]++ : num2[i]++;
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, num1[i] + num2[n] - num2[i]);
  }
  for (int l = 1; l <= n; l++) {
    int t = 1;
    int cnt1 = 0, cnt2 = 0;
    if (a[l] == 1)
      cnt1++;
    else
      cnt2++;
    for (int r = l + 1; r <= n; r++) {
      if (a[r] == 1) {
        cnt1++;
        t++;
      } else {
        cnt2++;
        if (cnt2 > t) {
          t = cnt2;
          cnt1 = 0;
        }
      }
      ans = max(ans, num1[l - 1] + num2[n] - num2[r] + t);
    }
  }
  cout << ans << endl;
  return 0;
}
