#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  int a[n];
  int ones[n + 2];
  int twos[n + 2];
  int twos1[n + 2];
  for (int i = 0; i < n + 2; i++) {
    ones[i] = 0;
    twos[i] = 0;
    twos1[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] == 1)
      ones[i] = 1;
    else
      twos[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    ones[i] = ones[i - 1] + ones[i];
  }
  for (int i = n; i >= 1; i--) {
    twos[i] = twos[i + 1] + twos[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, ones[i] + twos[i]);
  }
  for (int i = 1; i <= n; i++) {
    int max1 = 0;
    int max2 = 0;
    for (int j = 1; j <= i; j++) {
      max1 = max(max1, ones[j - 1] + twos[j] - twos[i + 1]);
    }
    for (int j = i + 1; j <= n; j++) {
      max2 = max(max2, twos[j] + ones[j] - ones[i]);
    }
    ans = max(ans, max1 + max2);
  }
  cout << ans << endl;
}
