#include <bits/stdc++.h>
using namespace ::std;
long long int p[3000];
long long int dp[5][3000];
long long int maxi(long long int a, long long int b) { return a <= b ? b : a; }
int main() {
  long long int i, j, k, n;
  cin >> n;
  long long int ans = 0;
  for (i = 1; i <= n; i++) {
    cin >> p[i];
    if (p[i] == 2) ans++;
  }
  long long int val1 = 0, val2 = 0, val3 = 0, val4 = 0;
  for (i = 1; i <= n; i++) {
    if (p[i] == 1)
      dp[1][i] = dp[1][i - 1] + 1;
    else
      dp[1][i] = dp[1][i - 1];
  }
  for (i = 1; i <= n; i++) {
    if (p[i] == 2) {
      long long int val = maxi(dp[2][i - 1], dp[1][i - 1]);
      dp[2][i] = maxi(dp[2][i - 1], dp[1][i - 1]) + 1;
    } else
      dp[2][i] = dp[2][i - 1];
  }
  for (i = 1; i <= n; i++) {
    if (p[i] == 1) {
      long long int val = maxi(dp[2][i - 1], dp[3][i - 1]);
      dp[3][i] = val + 1;
    } else
      dp[3][i] = dp[3][i - 1];
  }
  for (i = 1; i <= n; i++) {
    if (p[i] == 2) {
      long long int val = maxi(dp[3][i - 1], dp[4][i - 1]);
      dp[4][i] = val + 1;
    } else
      dp[4][i] = dp[4][i - 1];
  }
  ans = maxi(dp[4][n], dp[3][n]);
  ans = maxi(ans, maxi(dp[1][n], dp[2][n]));
  cout << ans << endl;
}
