#include <bits/stdc++.h>
using namespace std;
const int maxn = 2055;
int main() {
  int ma1 = 0, ma2 = 0, ma3 = 0, ma4 = 0, x, n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x == 1) {
      ++ma1;
      ma3 = max(ma3, ma2) + 1;
    } else {
      ma2 = max(ma1, ma2) + 1;
      ma4 = max(ma4, ma3) + 1;
    }
  }
  printf("%d\n", max(ma4, ma3));
}
