#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 2010;
int arr[N];
int dp[N][3];
int main(void) {
  int n, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
    dp[i][1] = dp[i - 1][1] + (arr[i] == 1);
  }
  for (i = n; i >= 1; --i) dp[i][2] = dp[i + 1][2] + (arr[i] == 2);
  int ans = 0;
  for (i = 1; i <= n; ++i) {
    ans = max(ans, dp[i][1] + dp[i][2]);
    int one = 0, two = 0;
    for (j = i; j <= n; ++j) {
      if (arr[j] == 2) {
        ++two;
        if (one) --one;
      } else {
        ++one;
      }
      ans = max(ans, dp[i - 1][1] + one + two + dp[j + 1][2]);
    }
  }
  cout << ans << endl;
  return 0;
}
