#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10, INF = 1e9 + 7;
int r[N][N], n, a[N], o[N], t[N];
int main() {
  ios_base::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++) {
    o[i] = o[i - 1];
    if (a[i] == 1) o[i]++;
  }
  for (int i = n; i >= 0; i--) {
    t[i] = t[i + 1];
    if (a[i] == 2) t[i]++;
  }
  for (int i = 1; i <= n; i++) {
    r[i][i] = 1;
    for (int j = i + 1; j <= n; j++) {
      r[i][j] = r[i][j - 1];
      if (a[j] == 1)
        r[i][j]++;
      else if (t[i - 1] - t[j + 1] > r[i][j])
        r[i][j] = t[i - 1] - t[j + 1];
    }
  }
  int MAX = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      MAX = max(o[i - 1] + r[i][j] + t[j + 1], MAX);
    }
  }
  cout << MAX << '\n';
  return 0;
}
