#include <bits/stdc++.h>
using namespace std;
long long fpow(long long n, long long k, long long p = 1000000007) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long inv(long long a, long long p = 1000000007) {
  return fpow(a, p - 2, p);
}
long long dp[4][100003];
int main() {
  long long n;
  long long a[100003];
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    if (i == 0) {
      if (a[i] == 1) {
        dp[0][0]++;
        dp[2][0]++;
      } else {
        dp[1][0]++;
        dp[3][0]++;
      }
      continue;
    }
    if (a[i] == 1) {
      dp[0][i] = dp[0][i - 1] + 1;
      dp[2][i] = max(dp[2][i - 1], dp[1][i - 1]) + 1;
      dp[1][i] = dp[1][i - 1];
      dp[3][i] = dp[3][i - 1];
    } else {
      dp[1][i] = max(dp[1][i - 1], dp[0][i - 1]) + 1;
      dp[3][i] = max(dp[2][i - 1], dp[3][i - 1]) + 1;
      dp[0][i] = dp[0][i - 1];
      dp[2][i] = dp[2][i - 1];
    }
  }
  cout << max(dp[0][n - 1], max(dp[1][n - 1], max(dp[2][n - 1], dp[3][n - 1])))
       << "\n";
}
