#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
int pre[maxn], suf[maxn], a[maxn];
int dp[maxn][maxn][3];
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] + (a[i] == 1);
  for (int i = n; i >= 1; --i) suf[i] = suf[i + 1] + (a[i] == 2);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      dp[i][j][2] = dp[i][j - 1][2] + (a[j] == 2);
      dp[i][j][1] = max(dp[i][j - 1][1], dp[i][j - 1][2]) + (a[j] == 1);
      ans = max(ans, max(dp[i][j][1], dp[i][j][2]) + pre[i - 1] + suf[j + 1]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
