#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 3;
int Arr[N], Res[5][N];
int A[5] = {0, 1, 2, 1, 2};
int main() {
  int n, x, y;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> Arr[i];
  for (int i = 1; i <= n + 1; i++) {
    for (int j = 1; j <= 4; j++) {
      Res[j][i] = max(Res[j][i - 1], Res[j - 1][i - 1]) + (Arr[i] == A[j]);
    }
  }
  cout << Res[4][n + 1] << "\n";
  return 0;
}
