#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
int n, a[maxn], dp1[maxn], dp2[maxn];
int maxx, l, r;
int main() {
  maxx = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) dp1[i] = dp1[i - 1] + (a[i] == 1);
  for (int i = n; i > 0; i--) dp2[i] = dp2[i + 1] + (a[i] == 2);
  for (int i = 1; i <= n; i++) maxx = max(maxx, dp1[i] + dp2[i]);
  for (int i = 1; i <= n; i++) {
    l = 0, r = 0;
    for (int j = i; j <= n; j++) {
      if (a[j] == 1)
        l++;
      else {
        r++;
        l--;
        if (l < 0) l = 0;
      }
      maxx = max(maxx, dp1[i - 1] + l + r + dp2[j + 1]);
    }
  }
  cout << maxx << endl;
  return 0;
}
