#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, a = 0, b = 0, c = 0, d = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == 1) {
      a++;
      c = max(c, b) + 1;
    } else {
      b = max(b, a) + 1;
      d = max(d, c) + 1;
    }
  }
  cout << max(c, d);
  return 0;
}
