#include <bits/stdc++.h>
using namespace std;
int n, a[2005], cnt1[2005], dp[2005][2], ni[2005][2], ans, dp0, dp1;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) cnt1[i] = cnt1[i - 1] + (a[i] == 1);
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] + (a[i] == 1);
    if (a[i] == 2)
      dp[i][1] = max(dp[i - 1][1] + 1, dp[i - 1][0] + 1);
    else
      dp[i][1] = dp[i - 1][1];
  }
  for (int i = 1; i <= n; i++) {
    ni[i][1] = ni[i + 1][1] + (a[i] == 2);
    if (a[i] == 1)
      ni[i][0] = max(ni[i + 1][0] + 1, ni[i + 1][1] + 1);
    else
      ni[i][0] = ni[i + 1][0];
  }
  for (int j = 1; j <= n; j++) {
    ans = max(ans, cnt1[j] + ni[j + 1][0]);
  }
  for (int j = 1; j <= n; j++) {
    ans = max(ans, dp[j - 1][1] + (n - j + 1 - (cnt1[n] - cnt1[j - 1])));
  }
  for (int i = 1; i <= n; i++) {
    dp0 = dp1 = 0;
    for (int j = i; j <= n; j++) {
      if (a[j] == 1)
        dp0 = max(dp1 + 1, dp0 + 1);
      else
        dp0 = dp0;
      dp1 = dp1 + (a[j] == 2);
      ans = max(ans, cnt1[i - 1] + dp0 + (n - j - (cnt1[n] - cnt1[j])));
    }
  }
  cout << ans;
  return 0;
}
