#include <bits/stdc++.h>
using namespace std;
int n;
int _(int x, int y) { return x > y ? x : y; }
int main() {
  scanf("%d", &n);
  int i, a = 0, b = 0, c = 0, d = 0, x;
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x == 1)
      a++, c++;
    else
      b++, d++;
    b = _(a, b);
    c = _(b, c);
    d = _(c, d);
  }
  printf("%d\n", d);
}
