#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e3 + 1;
int dp[MAX][4], in[MAX];
int main() {
  ios::sync_with_stdio(0);
  int n, ans = 1;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> in[i];
    if (in[i] == 1)
      dp[i][0] = 1;
    else
      dp[i][1] = 1;
    for (int j = 0; j < i; ++j) {
      if (in[i] == 1 && in[j] == 1) {
        dp[i][0] = max(dp[i][0], dp[j][0] + 1);
        dp[i][2] = max(dp[i][2], dp[j][2] + 1);
      }
      if (in[i] == 2 && in[j] == 2) {
        dp[i][1] = max(dp[i][1], dp[j][1] + 1);
        dp[i][3] = max(dp[i][3], dp[j][3] + 1);
      }
      if (in[i] == 1 && in[j] == 2) {
        dp[i][2] = max(dp[i][2], dp[j][1] + 1);
      }
      if (in[i] == 2 && in[j] == 1) {
        dp[i][1] = max(dp[i][1], dp[j][0] + 1);
        dp[i][3] = max(dp[i][3], dp[j][2] + 1);
      }
    }
    for (int j = 0; j < 4; ++j) ans = max(ans, dp[i][j]);
  }
  cout << ans << endl;
  return 0;
}
