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