#include <bits/stdc++.h>
using namespace std;
vector<int> pos1, pos2;
int dp[6] = {0};
int main() {
  int n, i, a;
  cin >> n;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    dp[1] += (a == 1);
    dp[2] = max(dp[1], dp[2] + (a == 2));
    dp[3] = max(dp[2], dp[3] + (a == 1));
    dp[4] = max(dp[3], dp[4] + (a == 2));
  }
  cout << dp[4] << endl;
}
