#include <bits/stdc++.h>
using namespace std;
int a[2005], pre1[2005], aft2[2005];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pre1[i] = pre1[i - 1] + (a[i] == 1);
  }
  for (int i = n; i >= 1; i--) aft2[i] = aft2[i + 1] + (a[i] == 2);
  int ans = 0;
  int kk, s1, s2;
  for (int k = 1; k <= n; k++) {
    int sum1 = 0, sum2 = 0;
    for (int i = 1; i <= k; i++)
      sum1 = max(sum1, pre1[i] + aft2[i] - aft2[k + 1]);
    for (int i = k; i <= n; i++)
      sum2 = max(sum2, aft2[i + 1] + pre1[i] - pre1[k]);
    if (ans < sum1 + sum2) {
      ans = sum1 + sum2;
      kk = k;
      s1 = sum1;
      s2 = sum2;
    }
  }
  cout << ans << endl;
  return 0;
}
