#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
int a, b, c, m, n, A[1 + MAXN], C[3][1 + MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
  }
  for (int i = 1; i <= n; ++i) {
    C[1][i] += C[1][i - 1];
    C[2][i] += C[2][i - 1];
    ++C[A[i]][i];
  }
  m = max(C[1][n], C[2][n]);
  for (int i = 1; i < n; ++i) {
    m = max(m, C[1][i] + C[2][n] - C[2][i]);
  }
  for (int i = 1; i < n; ++i) {
    a = 0;
    for (int j = i - 1; j >= 0; --j) {
      c = C[1][j] + C[2][i] - C[2][j];
      a = max(a, c);
    }
    b = 0;
    for (int j = i + 1; j <= n; ++j) {
      c = C[1][j] - C[1][i] + C[2][n] - C[2][j];
      b = max(b, c);
    }
    m = max(m, a + b);
  }
  cout << m << endl;
  return 0;
}
