#include <bits/stdc++.h>
int seq[2001];
std::map<int, int> amount[3];
int points[2001][2001][3];
int main() {
  int n;
  scanf("%d", &n);
  amount[1].insert(std::make_pair(0, 0));
  amount[2].insert(std::make_pair(0, 0));
  for (int i = 1; i <= n; i++) {
    int next;
    scanf("%d", &next);
    seq[i] = next;
    amount[next].insert(
        std::make_pair(i, std::prev(amount[next].end())->second + 1));
  }
  for (int start = 1; start <= n; start++) {
    points[start][0][1] = 0;
    points[start][0][2] = 0;
    for (int end = start; end <= n; end++) {
      if (seq[end] == 1) {
        points[start][end][1] = points[start][end - 1][1] + 1;
        points[start][end][2] = points[start][end - 1][2];
      } else {
        points[start][end][2] = points[start][end - 1][2] + 1;
        points[start][end][1] =
            std::max(points[start][end - 1][1], points[start][end][2]);
      }
    }
  }
  int best = 0;
  for (int start = 1; start <= n; start++) {
    for (int end = start; end <= n; end++) {
      int res = 0;
      res += std::prev(amount[1].lower_bound(start))->second;
      res += std::prev(amount[2].end())->second -
             std::prev(amount[2].lower_bound(end + 1))->second;
      res += points[start][end][1];
      best = std::max(best, res);
    }
  }
  printf("%d\n", best);
  return 0;
}
