#include <bits/stdc++.h>
using namespace std;
const int N = 2100;
int f[N][4];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    x--;
    for (int j = 0; j < 4; j++) {
      if (j)
        f[i][j] = f[i][j - 1];
      else
        f[i][j] = 0;
      int t = !((j & 1) ^ x);
      f[i][j] = max(f[i][j], f[i - 1][j] + t);
    }
  }
  cout << f[n][3] << endl;
  return 0;
}
