#include <bits/stdc++.h>
using namespace std;
int dp[2009][2009];
int a[2009], er[2009], tt[2009];
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int o = 0, t = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    er[i] = er[i - 1];
    tt[i] = tt[i - 1];
    if (a[i] == 1)
      o++;
    else
      t++;
    if (a[i] == 1)
      er[i]++;
    else
      tt[i]++;
  }
  int ans = o;
  for (int i = n - 1; i >= 0; i--) {
    int O = 0;
    for (int j = i; j < n; j++) {
      dp[i][j - i + 1] = dp[i + 1][j - i + 1];
      if (a[j] == 1) O++;
      dp[i][j - i + 1] = max(dp[i][j - i + 1], O);
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    ans = max(ans, er[i - 1] + t - tt[i - 1]);
    for (int j = i - 1; j >= 0; j--) {
      int o1 = dp[j][i - j];
      int orr = er[j - 1] + o1;
      ans = max(ans, orr + t - (i - orr));
    }
  }
  cout << ans << endl;
}
