#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
int f[2010][2010], n, a[2010], sum1[2010], sum2[2010];
int main() {
  scanf("%d", &n);
  for (register int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum1[i] = sum1[i - 1] + (a[i] == 1);
    sum2[i] = sum2[i - 1] + (a[i] == 2);
  }
  for (register int i = 1; i <= n; ++i) {
    register int now = i;
    f[i][i] = 1;
    for (register int j = i + 1; j <= n; ++j) {
      register int tmp;
      for (register int k = now; k <= j; ++k) {
        if (sum2[k] - sum2[i - 1] + sum1[j] - sum1[k] > f[i][j]) {
          f[i][j] = sum2[k] - sum2[i - 1] + sum1[j] - sum1[k];
          tmp = k;
        }
      }
      now = tmp;
    }
  }
  register int ans = 0;
  for (register int i = 1; i <= n; ++i) {
    for (register int j = i; j <= n; ++j) {
      ans = std::max(ans, sum1[i - 1] - sum1[0] + sum2[n] - sum2[j] + f[i][j]);
    }
  }
  printf("%d\n", ans);
}
