#include <bits/stdc++.h>
using namespace std;
vector<long long> G[800000];
long long a[800000], pre[800000], suf[800000];
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = pre[i - 1] + (a[i] == 1);
  }
  for (int i = n; i >= 2; i--) suf[i] = suf[i + 1] + (a[i] == 2);
  long long ones = 0, twos = 0, maxi = 0;
  for (int i = 1; i <= n; i++) {
    ones = 0, twos = 0;
    for (int j = i; j <= n; j++) {
      if (a[j] == 1)
        ones = max(ones, twos) + 1;
      else
        twos += 1;
      maxi = max(maxi, suf[j + 1] + pre[i - 1] + max(ones, twos));
    }
  }
  cout << maxi;
}
