#include <bits/stdc++.h>
#pragma GCC Optimize("Ofast")
using namespace std;
const long long maxn = 2e3 + 7;
const long long mod = 1e9 + 7;
const long long INF = 3e18 + 315;
long long n, a[maxn], dp[maxn][5];
template <typename... Args>
void input(Args&... args) {
  ((cin >> args), ...);
}
template <typename... Args>
void output(Args&... args) {
  ((cout << args), ...);
}
void no();
void yes();
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  input(n);
  for (long long i = 1; i <= n; i++) input(a[i]);
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j < 4; j++) {
      ((dp[i][j]) = max(dp[i][j], dp[i - 1][j]));
      if (j > 0) ((dp[i][j]) = max(dp[i][j], dp[i - 1][j - 1]));
      (!(j & 1) ? dp[i][j] += a[i] == 1 : dp[i][j] += a[i] == 2);
    }
  long long ans = -INF;
  for (long long i = 0; i < 4; i++) ((ans) = max(ans, dp[n][i]));
  output(ans, "\n");
  return 0;
}
void no() { cout << "NO" << endl; }
void yes() { cout << "YES" << endl; }
