#include <bits/stdc++.h>
using namespace std;
long long dp[3000][4];
long long a[3000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      dp[i][0] = dp[i - 1][0] + 1;
      dp[i][2] = max(dp[i - 1][2] + 1, dp[i][2]);
      dp[i][2] = max(dp[i][2], dp[i - 1][1] + 1);
      dp[i][1] = dp[i - 1][1];
      dp[i][3] = dp[i - 1][3];
    } else {
      dp[i][0] = dp[i - 1][0];
      dp[i][2] = dp[i - 1][2];
      dp[i][1] = max(dp[i - 1][1] + 1, dp[i][1]);
      dp[i][1] = max(dp[i][1], dp[i - 1][0] + 1);
      dp[i][3] = max(dp[i - 1][3] + 1, dp[i][3]);
      dp[i][3] = max(dp[i][3], dp[i - 1][2] + 1);
    }
  }
  cout << max(max(max(dp[n][3], dp[n][1]), dp[n][2]), dp[n][0]) << "\n";
}
