#include <bits/stdc++.h>
using namespace std;
const int N = 2111;
int n, a[N];
int dp[2][N][3];
void solve(int t) {
  for (int i = 1; i <= n; i++) {
    dp[t][i][1] = dp[t][i - 1][1] + (a[i] == 1);
    dp[t][i][2] = dp[t][i - 1][2];
    if (a[i] == 2) {
      dp[t][i][2] = max(dp[t][i - 1][1], dp[t][i - 1][2]) + 1;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  solve(0);
  reverse(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) a[i] = 3 - a[i];
  solve(1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int t1 = max(dp[0][i][1], dp[0][i][2]);
    int t2 = max(dp[1][n - i][1], dp[1][n - i][2]);
    ans = max(ans, t1 + t2);
  }
  cout << ans << endl;
  return 0;
}
