#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x7f7f7f7f7f7f;
template <typename _T>
void read(_T &x) {
  _T f = 1;
  x = 0;
  char s = getchar();
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
long long a[2005], n, ans;
long long sum1[2005], sum2[2005];
long long maxx[2005 << 2], val[2005 << 2];
void build(long long rt, long long l, long long r) {
  if (l == r) return (void)(maxx[rt] = val[l]);
  long long mid = l + r >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  maxx[rt] = max(maxx[rt << 1], maxx[rt << 1 | 1]);
}
long long query(long long rt, long long l, long long r, long long al,
                long long ar) {
  if (al <= l && r <= ar) return maxx[rt];
  long long mid = l + r >> 1, res = 0;
  if (al <= mid) res = max(res, query(rt << 1, l, mid, al, ar));
  if (ar > mid) res = max(res, query(rt << 1 | 1, mid + 1, r, al, ar));
  return res;
}
signed main() {
  read(n);
  for (long long i = 1; i <= n; i++)
    read(a[i]), sum1[i] = sum1[i - 1] + (a[i] == 1);
  for (long long i = n; i > 0; i--) sum2[i] = sum2[i + 1] + (a[i] == 2);
  for (long long i = 1; i <= n + 1; i++) val[i] = sum1[i - 1] + sum2[i];
  build(1, 1, n + 1);
  for (long long k = 1; k <= n + 1; k++) {
    long long tmp1 = query(1, 1, n + 1, 1, k) + query(1, 1, n + 1, k, n + 1);
    ans = max(ans, tmp1 - sum1[k - 1] - sum2[k]);
  }
  printf("%lld\n", ans);
  return 0;
}
