#include <bits/stdc++.h>
using namespace std;
int a[3000], n, ans, cnt, c[3000], d[3000], dp[3000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = n - 1; i >= 0; i--) {
    c[i] = c[i + 1];
    if (a[i] == 2) c[i]++;
  }
  for (int i = 0; i < n; i++) {
    if (i) d[i] = d[i - 1];
    if (a[i] == 1) d[i]++;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) continue;
    int cnt2 = 0, cnt1 = 0;
    int j = i;
    while (j < n) {
      if (a[j] == 2) {
        cnt2++;
        cnt1--;
      } else
        cnt1++;
      j++;
      if (cnt1 < 0) cnt1 = 0;
      ans = max(ans, cnt1 + cnt2 + d[i] + c[j]);
    }
  }
  int ans1 = 0;
  fill(dp, dp + n, 100000000);
  for (int i = 0; i < n; i++) {
    *upper_bound(dp, dp + n, a[i]) = a[i];
  }
  ans1 = lower_bound(dp, dp + n, 100000000) - dp;
  cout << max(ans1, ans);
  return 0;
}
