#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n, a[2001];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int dp[2001][4];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    if (a[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];
    }
    if (a[i] == 2) {
      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;
    }
  }
  int ans = 0;
  for (int i = 0; i < 4; i++) ans = max(ans, dp[n][i]);
  printf("%d\n", ans);
}
