#include <bits/stdc++.h>
using namespace std;
int a[2005];
int sum[3][2005];
int f[2005][2005][3];
int main() {
  int n, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) sum[1][i] = sum[1][i - 1] + (a[i] == 1);
  for (int i = n; i >= 1; i--) sum[2][i] = sum[2][i + 1] + (a[i] == 2);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      f[i][j][2] = f[i][j - 1][2] + (a[j] == 2);
      f[i][j][1] = max(f[i][j - 1][1], f[i][j - 1][2]) + (a[j] == 1);
      ans =
          max(ans, sum[1][i - 1] + sum[2][j + 1] + max(f[i][j][1], f[i][j][2]));
    }
  }
  printf("%d\n", ans);
  return 0;
}
