#include <bits/stdc++.h>
using namespace std;
int N;
int A[2050];
int sum1[2050], sum2[2050];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i <= N; i++) {
    if (A[i] == 1)
      sum1[i]++;
    else
      sum2[i]++;
    sum1[i] += sum1[i - 1];
    sum2[i] += sum2[i - 1];
  }
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int maxn1 = 0, maxn2 = 0;
    for (int j = 0; j <= i; j++)
      maxn1 = max(maxn1, sum1[j] + sum2[i] - sum2[j]);
    for (int j = i; j <= N; j++)
      maxn2 = max(maxn2, sum1[j] - sum1[i] + sum2[N] - sum2[j]);
    ans = max(ans, maxn1 + maxn2);
  }
  printf("%d\n", ans);
  return 0;
}
