#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e3 + 5;
int arr[MAX];
int twos[MAX][MAX], ones[MAX][MAX];
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = int(1); i < int(n + 1); i++) {
    cin >> arr[i];
  }
  for (int i = int(1); i < int(n + 1); i++) {
    for (int j = int(i); j < int(n + 1); j++) {
      ones[i][j] = ones[i][j - 1] + (arr[j] == 1);
      twos[i][j] = twos[i][j - 1] + (arr[j] == 2);
    }
  }
  int ans = 0;
  for (int i = int(1); i < int(n + 1); i++) {
    ans = max(ans, ones[1][i - 1] + twos[i][n]);
    ans = max(ans, ones[1][i] + twos[i + 1][n]);
  }
  for (int i = int(1); i < int(n + 1); i++) {
    int dp_ones = 0, dp_twos = 0;
    for (int j = int(i); j < int(n + 1); j++) {
      if (arr[j] == 1) {
        dp_ones = max(dp_ones, dp_twos) + 1;
      } else {
        dp_twos++;
      }
      int cur = ones[1][i - 1] + twos[j + 1][n] + max(dp_ones, dp_twos);
      ans = max(ans, cur);
    }
  }
  cout << ans << endl;
  return 0;
}
