#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 2, K = 19;
const int mod = 1e9 + 7;
int arr[N], rv[2020][2020][3], nx[2020][2020][3];
int max(int a, int b, int c) { return max(max(a, b), c); }
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", arr + i);
    arr[i]--;
  }
  int mx = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      rv[i + 1][j + 1][0] = !arr[j] + rv[i + 1][j][0];
      rv[i + 1][j + 1][1] = arr[j] + rv[i + 1][j][1];
      rv[i + 1][j + 1][2] =
          max(!arr[j] + rv[i + 1][j][0], arr[j] + rv[i + 1][j][2]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j >= 0; j--) {
      nx[j + 1][i + 1][0] = !arr[j] + nx[j + 2][i + 1][0];
      nx[j + 1][i + 1][1] = arr[j] + nx[j + 2][i + 1][1];
      nx[j + 1][i + 1][2] =
          max(!arr[j] + nx[j + 2][i + 1][0], arr[j] + nx[j + 2][i + 1][2]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int a = rv[1][i][2] + nx[i + 1][j + 1][1] + rv[j + 2][n][1];
      int b = rv[1][i][0] + nx[i + 1][j + 1][2] + rv[j + 2][n][1];
      int c = rv[1][i][0] + nx[i + 1][j + 1][0] + rv[j + 2][n][2];
      mx = max(mx, max(a, b, c));
    }
  }
  cout << mx;
  return 0;
}
