#include <bits/stdc++.h>
using namespace std;
int c[3055], a1[3055], a2[3055];
int dp[3055][3055][3];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  for (int i = 1; i <= n; i++) {
    a1[i] += a1[i - 1] + (c[i] == 1);
  }
  for (int i = n; i >= 1; i--) {
    a2[i] += a2[i + 1] + (c[i] == 2);
  }
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      dp[i][j][2] = dp[i][j - 1][2];
      dp[i][j][1] = dp[i][j - 1][1];
      if (c[j] == 2) dp[i][j][2] = dp[i][j - 1][2] + 1;
      if (c[j] == 1) dp[i][j][1] = max(dp[i][j - 1][1], dp[i][j - 1][2]) + 1;
    }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      ans = max(ans, a1[i - 1] + a2[j + 1] + dp[i][j][1]);
      ans = max(ans, a1[i - 1] + a2[j + 1] + dp[i][j][2]);
    }
  }
  cout << ans;
  return 0;
}
