#include <bits/stdc++.h>
using namespace std;
int N, A[2005];
int prc[2005], poc[2005];
int lds[2005][2005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> A[i];
  for (int i = 1; i <= N; i++) {
    lds[i][i] = 1;
    int c2 = (A[i] == 2);
    for (int j = i + 1; j <= N; j++) {
      if (A[j] == 2) {
        c2++;
        lds[i][j] = max(lds[i][j - 1], c2);
      } else {
        lds[i][j] = lds[i][j - 1] + 1;
      }
    }
  }
  for (int i = 1; i <= N; i++) prc[i] = prc[i - 1] + (A[i] == 1);
  for (int i = N; i >= 1; i--) poc[i] = poc[i + 1] + (A[i] == 2);
  int ans = 0;
  for (int i = 1; i <= N; i++)
    for (int j = i; j <= N; j++) {
      ans = max(ans, prc[i - 1] + lds[i][j] + poc[j + 1]);
    }
  cout << ans << '\n';
  return 0;
}
