#include <bits/stdc++.h>
using namespace std;
int a[2050];
int sum1[2050], sum2[2050];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      if (a[i] == 1) {
        sum1[i] = sum1[i - 1] + 1;
        sum2[i] = sum2[i - 1];
      }
      if (a[i] == 2) {
        sum2[i] = sum2[i - 1] + 1;
        sum1[i] = sum1[i - 1];
      }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int m1 = 0, m2 = 0;
      for (int j = 0; j <= i; j++) m1 = max(m1, sum1[j] + sum2[i] - sum2[j]);
      for (int j = i; j <= n; j++)
        m2 = max(m2, sum1[j] - sum1[i] + sum2[n] - sum2[j]);
      ans = max(ans, m1 + m2);
    }
    cout << ans << endl;
  }
  return 0;
}
