#include <bits/stdc++.h>
using namespace std;
long long a[2001];
long long cnt[2001], lis[2001], dp[2001][2001], cntr[2002];
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  cnt[0] = 0;
  for (int i = 1; i <= n; i++) cnt[i] = cnt[i - 1] + (a[i] == 1 ? 1 : 0);
  memset(dp, 0, sizeof dp);
  for (int i = 1; i <= n; i++) dp[i][i] = 1;
  for (int i = 1; i <= n; i++) lis[i] = 1;
  long long ans = max(cnt[n], n - cnt[n]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < i; j++)
      if (a[j] <= a[i]) lis[i] = max(lis[i], 1 + lis[j]);
  for (int i = 1; i <= n; i++) ans = max(ans, lis[i]);
  cntr[n + 1] = 0;
  if (a[n] == 1)
    cntr[n] = 1;
  else
    cntr[n] = 0;
  for (int j = n - 1; j >= 1; j--) cntr[j] = cntr[j + 1] + (a[j] == 1 ? 1 : 0);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      if (a[j] == 1)
        dp[i][j] = max(dp[i][j - 1] + 1, (cnt[j] - cnt[i - 1]));
      else
        dp[i][j] = max(dp[i][j - 1], (j - i + 1) - (cnt[j] - cnt[i - 1]));
    }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      ans = max(ans, cnt[i - 1] + dp[i][j] + (n - j) - cntr[j + 1]);
  cout << ans << endl;
  return 0;
}
