#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const long long mod = 1e9 + 7;
const long long INF = 1e18 + 5;
const double eps = 1e-9;
int n;
int a[maxn];
int pre1[maxn];
int pre2[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    pre1[i] = pre1[i - 1] + (a[i] == 1);
  }
  for (int i = n; i >= 1; i--) pre2[i] = pre2[i + 1] + (a[i] == 2);
  int ans = 0;
  for (int k = 1; k <= n + 1; k++) {
    int num1 = 0, num2 = 0;
    for (int i = 1; i <= k; i++)
      num1 = max(num1, pre1[i - 1] + pre2[i] - pre2[k]);
    for (int i = k; i <= n + 1; i++)
      num2 = max(num2, pre2[i] + pre1[i - 1] - pre1[k - 1]);
    ans = max(ans, num1 + num2);
  }
  printf("%d\n", ans);
}
