#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 5;
int f[3][maxn], g[3][maxn], a[maxn];
int n, ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) {
      f[1][i] = f[1][i - 1] + 1;
      f[2][i] = f[2][i - 1];
      f[2][i] = max(f[1][i], f[2][i]);
    } else if (a[i] == 2) {
      f[1][i] = f[1][i - 1];
      f[2][i] = f[2][i - 1] + 1;
      f[2][i] = max(f[1][i], f[2][i]);
    }
  for (int i = 0; i < n; i++) {
    memset(g, (0), sizeof(g));
    for (int j = i + 1; j <= n; j++)
      if (a[j] == 1) {
        g[1][j] = g[1][j - 1] + 1;
        g[2][j] = g[2][j - 1];
        g[2][j] = max(g[1][j], g[2][j]);
      } else if (a[j] == 2) {
        g[1][j] = g[1][j - 1];
        g[2][j] = g[2][j - 1] + 1;
        g[2][j] = max(g[1][j], g[2][j]);
      }
    ans = max(ans, f[2][i] + g[2][n]);
  }
  cout << ans << endl;
  return 0;
}
