#include <bits/stdc++.h>
using namespace std;
void chmax(int& a, int b) { a = max(a, b); }
int main() {
  int N, A[2000];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  static int dp[2001][4];
  vector<int> C = {1, 2, 1, 2};
  for (int i = 0; i < N; i++)
    for (int j = 0; j < 4; j++)
      for (int k = j; k < 4; k++)
        chmax(dp[i + 1][k], dp[i][j] + (A[i] == C[k]));
  int ans = 0;
  for (int j = 0; j < 4; j++) chmax(ans, dp[N][j]);
  cout << ans << endl;
  return 0;
}
