#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
int a[N], f[N][N][3], d[N][N][3];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j)
      if (a[j] == 1) {
        f[i][j][1] = f[i][j - 1][1] + 1;
        f[i][j][2] = f[i][j - 1][2];
        d[i][j][1] = max(d[i][j - 1][1], d[i][j - 1][2]) + 1;
        d[i][j][2] = d[i][j - 1][2];
      } else {
        f[i][j][1] = f[i][j - 1][1];
        f[i][j][2] = max(f[i][j - 1][1], f[i][j - 1][2]) + 1;
        d[i][j][1] = d[i][j - 1][1];
        d[i][j][2] = d[i][j - 1][2] + 1;
      }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) {
      ans = max(ans, f[1][i - 1][1] + f[i][j][1] + f[j + 1][n][2]);
      ans = max(ans, f[1][i - 1][1] + d[i][j][1] + f[j + 1][n][2]);
      ans = max(ans, f[1][i - 1][2] + d[i][j][2] + f[j + 1][n][2]);
    }
  cout << ans;
}
