#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int mod = 1e9 + 7;
int dp[maxn][3];
int n, a[maxn];
int get(int flag, int l, int r) {
  if (l > r) return 0;
  return dp[r][flag] - dp[l - 1][flag];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    dp[i][a[i]]++;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 2; j++) dp[i][j] += dp[i - 1][j];
  int ans = 0;
  for (int r = 1; r <= n; r++) {
    int mx1 = 0, mx2 = 0;
    for (int l = 0; l <= r; l++) {
      mx1 = max(mx1, get(1, 1, l) + get(2, l + 1, r));
    }
    for (int l = r + 1; l <= n; l++) {
      mx2 = max(mx2, get(1, r + 1, l) + get(2, l + 1, n));
    }
    ans = max(ans, mx1 + mx2);
  }
  printf("%d\n", ans);
  return 0;
}
