#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3;
int dp[maxn + 5][4], a[maxn + 5], n;
void f() {
  for (int i = (1); i <= (n); i++) {
    dp[i][0] = dp[i - 1][0] + (a[i] == 1);
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + (a[i] == 2);
    dp[i][2] = max(dp[i - 1][1], dp[i - 1][2]) + (a[i] == 1);
    dp[i][3] = max(dp[i - 1][2], dp[i - 1][3]) + (a[i] == 2);
  }
}
void solve() {
  cin >> n;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  f();
  cout << max(dp[n][2], dp[n][3]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(8);
  clock_t b = clock();
  solve();
  clock_t e = clock();
  cerr << (double(e - b) / CLOCKS_PER_SEC) << " sec";
  return 0;
}
