#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int N = 2e3 + 5;
int pre[N], en[N], a[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  en[n + 1] = pre[0] = 0;
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (a[i] == 1);
  for (int i = n; i >= 1; i--) en[i] = en[i + 1] + (a[i] == 2);
  int cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    cnt1 = cnt2 = 0;
    for (int j = i; j <= n; j++) {
      cnt2 += (a[j] == 2);
      cnt1 = max(cnt2, cnt1) + (a[j] == 1);
      ans = max(ans, max(cnt1, cnt2) + pre[i - 1] + en[j + 1]);
    }
  }
  cout << ans << endl;
  return 0;
}
