#include <bits/stdc++.h>
using namespace std;
int input[2002], n;
int ones[2002], twos[2002], ll[2002], rr[2002];
void prepare() {
  int i;
  ones[0] = input[0] == 1;
  twos[0] = 1 - ones[0];
  for (i = 1; i < n; i++) {
    ones[i] = ones[i - 1] + (input[i] == 1);
    twos[i] = i + 1 - ones[i];
  }
  for (i = 0; i < n; i++) {
    ll[i] = 0;
    rr[i] = 0;
  }
}
int getones(int l, int r) {
  if (l > 0)
    return ones[r] - ones[l - 1];
  else
    return ones[r];
}
int gettwos(int l, int r) {
  if (l > 0)
    return twos[r] - twos[l - 1];
  else
    return twos[r];
}
int main() {
  cin >> n;
  int i, j;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> input[i];
  prepare();
  for (i = 0; i < n; i++)
    for (j = 0; j <= i; j++) ll[i] = max(ll[i], getones(0, j) + gettwos(j, i));
  for (i = 0; i < n; i++)
    for (j = i; j < n; j++)
      rr[i] = max(rr[i], getones(i, j) + gettwos(j, n - 1));
  int out = 0;
  for (i = 0; i < n - 1; i++) out = max(out, ll[i] + rr[i + 1]);
  out = max(out, ll[n - 1]);
  cout << out;
  return 0;
}
