#include <bits/stdc++.h>
using namespace std;
const int MAX = 2010;
int seq[4];
int a[MAX];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) {
    seq[3] = max(seq[2], seq[3]) + (a[i] == 2);
    seq[2] = max(seq[1], seq[2]) + (a[i] == 1);
    seq[1] = max(seq[1], seq[0]) + (a[i] == 2);
    seq[0] += (a[i] == 1);
  }
  printf("%d\n", max(seq[3], seq[2]));
  return 0;
}
