#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, mx1 = 0, mx2 = 0, mx3 = 0, mx4 = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    if (a == 1) {
      mx1++;
      mx3 = max(mx3, mx2) + 1;
    } else {
      mx2 = max(mx2, mx1) + 1;
      mx4 = max(mx4, mx3) + 1;
    }
  }
  printf("%d\n", max(mx3, mx4));
  return 0;
}
