#include <bits/stdc++.h>
using namespace std;
int n;
int a[2005];
int dp1[2005], dp2[2005];
int dp3[2005], dp4[2005];
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 1; i <= n; i++) {
      dp1[i] = dp1[i - 1];
      if (a[i] == 1) dp1[i]++;
      if (a[i] == 2)
        dp3[i] = 1;
      else
        dp3[i] = -1;
      if (dp3[i - 1] > 0) dp3[i] += dp3[i - 1];
    }
    for (int i = n; i >= 1; i--) {
      dp2[i] = dp2[i + 1];
      if (a[i] == 2) dp2[i]++;
      if (a[i] == 1)
        dp4[i] = 1;
      else
        dp4[i] = -1;
      if (dp4[i + 1] > 0) dp4[i] += dp4[i + 1];
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int tans = dp1[i] + dp2[i] + dp3[i] + dp4[i];
      ans = max(ans, tans);
    }
    printf("%d\n", ans);
  }
}
