#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int arr[N];
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  if (n == 1) {
    cout << 1;
    return 0;
  }
  int cnt2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i] == 2) {
      cnt2++;
    }
  }
  int fin_result = 0;
  int tcnt1 = 0, tcnt2 = 0;
  for (int i = 0; i < n; i++) {
    tcnt1 = tcnt2 = 0;
    for (int j = 0; j < i; j++) {
      if (arr[j] == 1) tcnt1++;
    }
    for (int j = i + 1; j < n; j++) {
      if (arr[j] == 2) tcnt2++;
    }
    fin_result = max(fin_result, tcnt1 + tcnt2 + 1);
  }
  int cnt1 = 0;
  int dp_1 = 0, dp_2 = 0;
  for (int i = 0; i < n; i++) {
    dp_1 = dp_2 = 0;
    int temp_result = 0;
    if (arr[i] == 2) {
      dp_2 = 1;
      cnt2--;
    } else if (arr[i] == 1) {
      dp_1 = 1;
    }
    int tmp = cnt2;
    for (int j = i + 1; j < n; j++) {
      if (arr[j] == 1) {
        dp_1 = max(dp_1, dp_2) + 1;
      } else if (arr[j] == 2) {
        dp_2++;
        tmp--;
      }
      temp_result = max(temp_result, cnt1 + max(dp_1, dp_2) + tmp);
    }
    if (arr[i] == 1) {
      cnt1++;
    }
    fin_result = max(fin_result, temp_result);
  }
  cout << fin_result << "\n";
}
