#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  vector<int> one(n + 1), two(n + 1);
  for (int i = 1; i <= n; ++i) {
    one[i] = one[i - 1] + (a[i] == 1);
    two[i] = two[i - 1] + (a[i] == 2);
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    int b1 = 0, b2 = 0;
    for (int j = 0; j <= i; ++j) b1 = max(b1, one[j] + two[i] - two[j]);
    for (int j = i; j <= n; ++j)
      b2 = max(b2, one[j] - one[i] + two[n] - two[j]);
    ans = max(ans, b1 + b2);
  }
  cout << ans;
  return 0;
}
