#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long a[2005];
long long dp[2005][4];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0];
    dp[i][1] = dp[i - 1][1];
    dp[i][2] = dp[i - 1][2];
    dp[i][3] = dp[i - 1][3];
    if (a[i] == 1) {
      dp[i][0]++;
      dp[i][2] = max(dp[i][2], dp[i - 1][0] + 1);
      dp[i][2] = max(dp[i][2], dp[i - 1][1] + 1);
      dp[i][2] = max(dp[i][2], dp[i - 1][2] + 1);
    } else {
      dp[i][1] = max(dp[i][1], dp[i - 1][0] + 1);
      dp[i][1] = max(dp[i][1], dp[i - 1][1] + 1);
      dp[i][1] = 1 + max(dp[i - 1][0], dp[i - 1][1]);
      dp[i][3] = max(dp[i][3], dp[i - 1][0] + 1);
      dp[i][3] = max(dp[i][3], dp[i - 1][1] + 1);
      dp[i][3] = max(dp[i][3], dp[i - 1][2] + 1);
      dp[i][3] = max(dp[i][3], dp[i - 1][3] + 1);
    }
  }
  cout << max(dp[n][3], dp[n][2]) << endl;
}
