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