#include <bits/stdc++.h>
using namespace std;
int o[2005], t[2005];
int to[2005][2005][2];
int a[2005];
int n;
void solve() {
  for (int i = 1; i <= n; i++) {
    o[i] = o[i - 1] + ((a[i] == 1) ? 1 : 0);
  }
  for (int j = n; j >= 1; j--) {
    t[j] = t[j + 1] + ((a[j] == 2) ? 1 : 0);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      if (a[j] == 2) {
        to[i][j][1] = to[i][j - 1][1] + 1;
        to[i][j][0] = to[i][j - 1][0];
      } else {
        to[i][j][0] = max(to[i][j - 1][0] + 1, to[i][j - 1][1] + 1);
        to[i][j][1] = to[i][j - 1][1];
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      ans = max(o[i - 1] + max(to[i][j][0], to[i][j][1]) + t[j + 1], ans);
    }
  }
  cout << ans << endl;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  solve();
  return 0;
}
