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