#include <bits/stdc++.h>
using namespace std;
const int ms = 2e3 + 200;
int v[ms], cnt[2][ms];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", v + i);
    v[i]--;
    cnt[v[i]][i]++;
  }
  for (int i = 1; i < n; i++) {
    cnt[0][i] += cnt[0][i - 1];
  }
  for (int i = n - 2; i > -1; i--) {
    cnt[1][i] += cnt[1][i + 1];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int c1 = v[i];
    int ma = 1;
    ans = max(ans, cnt[0][i] + cnt[1][i]);
    for (int j = i + 1; j < n; j++) {
      if (v[j] == 0) ma++;
      ma = max(ma, c1 + 1);
      if (v[j] == 1) c1++;
      ans = max(ans, (i ? cnt[0][i - 1] : 0) + cnt[1][j + 1] + ma);
    }
  }
  cout << ans << endl;
}
