#include <bits/stdc++.h>
using namespace std;
inline int rit() {
  int f = 0, key = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') key = -1;
  } while (ch < '0' || ch > '9');
  do {
    f = f * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return f * key;
}
int n;
int arr[2000 + 5], suf[2000 + 5], pre[2000 + 5], ans, dp[2000 + 5][2000 + 5][3];
int32_t main(void) {
  n = rit();
  for (int i = 1; i <= (n); i++) {
    arr[i] = rit();
  }
  for (int i = 1; i <= (n); i++) {
    pre[i] = pre[i - 1] + (arr[i] == 1);
    suf[n - i + 1] = suf[n - i + 2] + (arr[n - i + 1] == 2);
  }
  for (int i = 1; i <= (n); i++)
    for (int j = i; j <= n; ++j) {
      dp[i][j][1] = max(dp[i][j - 1][1], dp[i][j - 1][2]) + (arr[j] == 1);
      dp[i][j][2] = dp[i][j - 1][2] + (arr[j] == 2);
      ans = max(ans, max(dp[i][j][1], dp[i][j][2]) + pre[i - 1] + suf[j + 1]);
    }
  printf("%d\n", ans);
  return 0;
}
