#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(10);
  cout << fixed;
  int n;
  cin >> n;
  int dp[4] = {0};
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    dp[3] = max(dp[2], dp[3]);
    if (x == 2) {
      dp[3]++;
    }
    dp[2] = max(dp[1], dp[2]);
    if (x == 1) {
      dp[2]++;
    }
    dp[1] = max(dp[0], dp[1]);
    if (x == 2) {
      dp[1]++;
    }
    if (x == 1) {
      dp[0]++;
    }
  }
  int ans = max(dp[2], dp[3]);
  cout << ans;
}
