#include <bits/stdc++.h>
using namespace std;
long long powm(long long base, long long exp, long long mod = 1000000007) {
  long long ans = 1;
  while (exp) {
    if (exp & 1) ans = (ans * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return ans;
}
long long ctl(char x, char an = 'a') { return (long long)(x - an); }
char ltc(long long x, char an = 'a') { return (char)(x + 'a'); }
long long a[2005];
long long cnt[2005][2005];
long long pre[2005], suff[2005];
int main() {
  long long n, ans = 0;
  cin >> n;
  for (long long i = 1; i < n + 1; i++) cin >> a[i];
  long long c1 = 0, c2 = 0;
  for (long long i = 1; i < n + 1; i++)
    c1 += (a[i] == 1), pre[i] = pre[i - 1] + (a[i] == 1);
  for (long long i = 1; i < n + 1; i++) c2 += (a[i] == 2);
  for (long long i = n; i >= 1; i--) suff[i] = suff[i + 1] + (a[i] == 2);
  ans = max(c1, c2);
  for (long long i = n; i >= 1; i--) {
    long long cnt1 = 0, cnt2 = 0;
    for (long long j = i; j >= 1; j--) {
      if (a[j] == 1)
        cnt1++;
      else
        cnt2 = max(cnt2, cnt1) + 1;
      cnt[j][i] = cnt2;
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = i; j < n + 1; j++) {
      ans = max(ans, pre[i - 1] + cnt[i][j] + suff[j + 1]);
    }
  }
  cout << ans;
  return 0;
}
