#include <bits/stdc++.h>
using namespace std;
int b[100100];
int a, ab, aba, abab;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    if (b[i] == 1) {
      a++;
      aba++;
    } else {
      ab++;
      abab++;
    }
    ab = max(a, ab);
    aba = max(ab, aba);
    abab = max(aba, abab);
  }
  cout << abab;
  return 0;
}
