#include <bits/stdc++.h>
using namespace std;
int n, a[2005], dp[2005][2005], psum[2005][2], maxlen;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    psum[i + 1][0] = psum[i][0];
    psum[i + 1][1] = psum[i][1];
    if (a[i] == 1)
      psum[i + 1][0]++;
    else
      psum[i + 1][1]++;
  }
  for (int i = 0; i < n; i++)
    for (int j = i; j < n; j++) {
      if (i == j)
        dp[i][j] = 1;
      else if (a[j] == 1)
        dp[i][j] = dp[i][j - 1] + 1;
      else
        dp[i][j] = max(psum[j + 1][1] - psum[i][1], dp[i][j - 1]);
      maxlen =
          max(maxlen, psum[i][0] + dp[i][j] + (psum[n][1] - psum[j + 1][1]));
    }
  cout << maxlen << '\n';
}
