#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
const int maxm = 110;
const int mod = 1e9 + 7;
int N, er[maxn], dp[maxn][2][3], ans = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> er[i];
  for (int i = N; i > 0; i--) {
    dp[i][0][er[i]] = 1;
    for (int j = i + 1; j <= N; j++) {
      if (er[i] <= er[j])
        (dp[i][0][er[i]]) = max((dp[i][0][er[i]]), (dp[j][0][er[j]] + 1));
      (dp[i][0][er[j]]) = max((dp[i][0][er[j]]), (dp[j][0][er[j]]));
    }
  }
  for (int i = 1; i <= N; i++) {
    dp[i][1][er[i]] = 1;
    for (int j = i - 1; j > 0; j--) {
      if (er[j] <= er[i])
        (dp[i][1][er[i]]) = max((dp[i][1][er[i]]), (dp[j][1][er[j]] + 1));
      (dp[i][1][er[j]]) = max((dp[i][1][er[j]]), (dp[j][1][er[j]]));
    }
  }
  for (int i = 1; i <= N; i++) {
    (ans) = max((ans), (dp[i][0][1]));
    (ans) = max((ans), (dp[i][0][2]));
    (ans) = max((ans), (dp[i][1][1]));
    (ans) = max((ans), (dp[i][1][2]));
    int temp[3][3] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
    temp[er[i]][er[i]] = 1;
    for (int j = i + 1; j <= N; j++) {
      if (er[j] == 1) {
        temp[1][1]++;
        temp[2][1]++;
        (temp[2][1]) = max((temp[2][1]), (temp[2][2] + 1));
      } else
        temp[2][2]++;
      (ans) = max((ans), (temp[1][1] + dp[i - 1][1][1] +
                          max(dp[j + 1][0][1], dp[j + 1][0][2])));
      (ans) = max((ans), (temp[2][2] + dp[j + 1][0][2] +
                          max(dp[i - 1][1][1], dp[i - 1][1][2])));
      (ans) = max((ans), (temp[2][1] + dp[i - 1][1][1] + dp[j + 1][0][2]));
    }
  }
  cout << ans << '\n';
  return 0;
}
