#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a = 0, b = 0, c = 0, d = 0;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x == 1) {
      a++;
      c = max(b, c) + 1;
    } else {
      b = max(a, b) + 1;
      d = max(c, d) + 1;
    }
  }
  cout << max(a, max(b, max(c, d))) << '\n';
  return 0;
}
