#include <bits/stdc++.h>
using namespace std;
int a[2010], dp[2010][4];
int mx[4];
int solve(int n) {
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 4; j++) dp[i][j] = 0;
  for (int j = 0; j < 4; j++) mx[j] = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1)
      dp[i][0] = 1 + mx[0];
    else
      dp[i][0] = mx[0];
    if (a[i] == 1)
      dp[i][2] = 1 + max(mx[2], mx[1]);
    else
      dp[i][2] = mx[2];
    if (a[i] == 2)
      dp[i][1] = 1 + max(mx[1], mx[0]);
    else
      dp[i][1] = mx[1];
    if (a[i] == 2)
      dp[i][3] = 1 + max(mx[3], mx[2]);
    else
      dp[i][3] = mx[3];
    for (int j = 0; j < 4; j++) mx[j] = max(mx[j], dp[i][j]);
  }
  int ans = 0;
  for (int j = 0; j < 4; j++) ans = max(ans, mx[j]);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << solve(n) << endl;
  return 0;
}
