#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323846;
const long long M = 1e18 + 7;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const int mod = 998244353;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n + 1);
  for (long long i = 1; i < (n + 1); ++i) {
    cin >> v[i];
  }
  int ans = 0;
  for (long long i = 1; i < (n + 1); ++i) {
    int ans1 = 0, ans2 = 0, c = 0;
    for (long long j = 1; j < (i + 1); ++j) {
      if (v[j] == 1) c++;
    }
    ans1 = max(ans1, c);
    for (long long j = (i + 1 - 1); j >= (1); --j) {
      if (v[j] == 1)
        c--;
      else
        c++;
      ans1 = max(ans1, c);
    }
    c = 0;
    for (long long j = i + 1; j < (n + 1); ++j) {
      if (v[j] == 2) c++;
    }
    for (long long j = i + 1; j < (n + 1); ++j) {
      if (v[j] == 2)
        c--;
      else
        c++;
      ans2 = max(ans2, c);
    }
    ans = max(ans, ans1 + ans2);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
