#include <bits/stdc++.h>
using namespace std;
const int MX = 2e3 + 10;
const int ch[5] = {0, 1, 2, 1, 2};
int n, dp[5][MX], a[MX];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= 4; ++j) {
      dp[j][i] = max(dp[j - 1][i], dp[j][i - 1] + (int)(a[i] == ch[j]));
    }
  printf("%d", dp[4][n]);
}
