#include <bits/stdc++.h>
using namespace std;
int one[2002], two[2002];
int dp[2002][2002][2][2];
int main() {
  int n;
  cin >> n;
  int ar[n + 2];
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    one[i] = one[i - 1] + (ar[i] == 1);
    two[i] = two[i - 1] + (ar[i] == 2);
  }
  two[n + 1] = two[n];
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      dp[i][j][0][0] = dp[i][j - 1][0][0];
      dp[i][j][0][1] = dp[i][j - 1][0][1];
      dp[i][j][1][0] = dp[i][j - 1][1][0];
      dp[i][j][1][1] = dp[i][j - 1][1][1];
      if (ar[j] == 1) {
        dp[i][j][0][0]++;
        dp[i][j][1][1] = max(dp[i][j][1][1], dp[i][j][1][0]) + 1;
      } else {
        dp[i][j][1][0]++;
        dp[i][j][0][1] = max(dp[i][j][0][1], dp[i][j][0][0]) + 1;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int fxd = one[i - 1] + two[n + 1] - two[j];
      int flip = max(max(dp[i][j][0][0], dp[i][j][0][1]),
                     max(dp[i][j][1][0], dp[i][j][1][1]));
      ans = max(ans, fxd + flip);
    }
  }
  cout << ans << endl;
  return 0;
}
