#include <bits/stdc++.h>
using namespace std;
int n, x, f[5];
int main() {
  scanf("%d", &n);
  for (register int(i) = (1); (i) <= (n); (i)++)
    scanf("%d", &x), f[1] += (x == 1), f[2] = max(f[1], f[2] + (x == 2)),
                                       f[3] = max(f[2], f[3] + (x == 1)),
                                       f[4] = max(f[3], f[4] + (x == 2));
  cout << f[4];
  return 0;
}
