#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long best[2222][2222];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> a(n + 1), ones(n + 1), twos(n + 1);
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    ones[i] = ones[i - 1] + (a[i] == 1);
    twos[i] = twos[i - 1] + (a[i] == 2);
  }
  for (long long i = 1; i <= n; ++i) {
    best[i][i] = 1;
    long long t = (a[i] == 2);
    for (long long j = i - 1; j >= 1; --j) {
      best[i][j] = best[i][j + 1];
      if (a[j] == 2) {
        best[i][j] = max(best[i][j], t + 1);
        ++t;
      } else {
        ++best[i][j];
      }
    }
    t = (a[i] == 2);
    for (long long j = i + 1; j <= n; ++j) {
      best[i][j] = best[i][j - 1];
      if (a[j] == 2) {
        best[i][j] = max(best[i][j], t + 1);
        ++t;
      } else {
        ++best[i][j];
      }
    }
  }
  long long ans = 0;
  for (long long l = 1; l <= n; ++l)
    for (long long r = l; r <= n; ++r) {
      long long res1 = 0, res2 = 0, res3 = 0;
      if (l > 1) {
        res1 += best[l - 1][1];
        res2 += ones[l - 1];
        res3 += ones[l - 1];
      }
      res1 += twos[r] - twos[l - 1];
      res2 += best[l][r];
      res3 += ones[r] - ones[l - 1];
      if (r < n) {
        res1 += twos[n] - twos[r];
        res2 += twos[n] - twos[r];
        res3 += best[n][r + 1];
      }
      ans = max({ans, res1, res2, res3});
    }
  cout << ans << endl;
}
