#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
int max(int a, int b) { return a > b ? a : b; }
const int maxn = 2000 + 10;
int n;
int a[maxn];
int front1[maxn], back1[maxn], front2[maxn], back2[maxn];
int rec[maxn];
int next2[maxn], next1[maxn];
int main() {
  int ans = 0;
  int cnt1 = 0, cnt2 = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    front1[i] = cnt1;
    front2[i] = cnt2;
    if (a[i] == 1)
      cnt1++;
    else
      cnt2++;
  }
  cnt1 = cnt2 = 0;
  for (int i = n - 1; i >= 0; i--) {
    back1[i] = cnt1;
    back2[i] = cnt2;
    if (a[i] == 1)
      cnt1++;
    else
      cnt2++;
  }
  for (int i = 0; i < n; i++) {
    int tem1 = 0, tem2 = 0;
    for (int l = 0; i - l >= 0; l++)
      tem1 = max(tem1, front1[i - l] + front2[i] - front2[i - l]);
    for (int r = 0; r + i < n; r++)
      tem2 = max(tem2, back2[r + i] + back1[i] - back1[i + r]);
    ans = max(ans, tem1 + tem2 + 1);
  }
  cout << ans << endl;
}
