#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
using ii = pair<long long int, long long int>;
class prioritize {
 public:
  bool operator()(ii &p1, ii &p2) { return p1.first < p2.first; }
};
auto start_time = high_resolution_clock::now();
void time() { return; }
void ojudge() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  return;
}
int main() {
  ojudge();
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int s1 = 0, s12 = 0, s121 = 0, s1212 = 0, s2 = 0, s21 = 0, s212 = 0;
  for (long long int i = 0; i < n; i++) {
    if (a[i] == 1) {
      s1++;
      s121++;
      s121 = max(s121, 1 + s12);
      if (s21) s21++;
      if (s2) s21 = max(s21, s2 + 1);
    } else {
      s2++;
      s12++;
      s12 = max(s12, 1 + s1);
      if (s1212) s1212++;
      s1212 = max({s1212, s1 + 1, s121 + 1});
    }
  }
  cout << max({s1, s1212, s2, s21, s12, s121}) << "\n";
  time();
  return 0;
}
