#include <bits/stdc++.h>
using namespace std;
int a[2005], pre[2005], lst[2005], dp[2005][2];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) {
    pre[i] = pre[i - 1];
    if (a[i] == 1) ++pre[i];
  }
  for (int i = n; i; --i) {
    lst[i] = lst[i + 1];
    if (a[i] == 2) ++lst[i];
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    memset(dp, 0, sizeof(dp));
    for (int j = i + 1; j <= n; ++j) {
      dp[j][0] = dp[j - 1][0];
      dp[j][1] = dp[j - 1][1];
      if (a[j] == 1)
        dp[j][0] = max(dp[j][0] + 1, dp[j - 1][1] + 1);
      else
        ++dp[j][1];
    }
    for (int j = i + 1; j <= n + 1; ++j) {
      ans = max(ans, pre[i] + lst[j] + max(dp[j - 1][0], dp[j - 1][1]));
    }
  }
  printf("%d\n", ans);
  return 0;
}
