#include <bits/stdc++.h>
using namespace ::std;
long long int p[3000];
long long int dp[5][3000];
long long int maxi(long long int a, long long int b) { return a <= b ? b : a; }
int main() {
  long long int i, j, k, n;
  cin >> n;
  long long int ans = 0;
  for (i = 1; i <= n; i++) {
    cin >> p[i];
    if (p[i] == 2) ans++;
  }
  long long int val1 = 0, val2 = 0, val3 = 0, val4 = 0;
  for (i = 1; i <= n; i++) {
    if (p[i] == 1) {
      val3 = maxi(val3, val2) + 1;
      val1++;
    } else {
      val4 = maxi(val4, val3) + 1;
      val2 = maxi(val2, val1) + 1;
    }
  }
  ans = maxi(val1, val2);
  ans = maxi(ans, maxi(val3, val4));
  cout << ans << endl;
}
