#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int dp[n][4];
  memset(dp, 0, sizeof(dp));
  if (arr[0] == 1) {
    dp[0][0] = 1;
    dp[0][2] = 1;
  } else {
    dp[0][1] = 1;
    dp[0][3] = 1;
  }
  for (int i = 1; i < n; i++) {
    if (arr[i] == 1) {
      dp[i][0] = dp[i - 1][0] + 1;
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = max(dp[i - 1][1], dp[i - 1][2]) + 1;
      dp[i][3] = dp[i - 1][3];
    } else {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
      dp[i][2] = dp[i - 1][2];
      dp[i][3] = max(dp[i - 1][2], dp[i - 1][3]) + 1;
    }
  }
  cout << max(dp[n - 1][2], dp[n - 1][3]);
}
