#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 5;
const long long mod = 1e9 + 7;
long long dx[] = {0, 0, -1, 1, -1, -1, 1, 1};
long long dy[] = {1, -1, 0, 0, 1, -1, -1, 1};
long long dp[N][5], pat[5] = {0, 1, 2, 1, 2};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, ans = 0;
  cin >> n;
  long long arr[n];
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= 4; j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + (arr[i] == pat[j]);
    }
  }
  for (long long i = 1; i <= 4; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans;
}
