#include <bits/stdc++.h>
using namespace std;
int a[2005][4];
int main() {
  int n, num;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num;
    if (num == 1) {
      a[i][0] = a[i - 1][0] + 1;
      a[i][1] = a[i - 1][1];
      a[i][2] = max(a[i - 1][2], a[i - 1][1]) + 1;
      a[i][3] = a[i - 1][3];
    } else {
      a[i][0] = a[i - 1][0];
      a[i][1] = max(a[i - 1][0], a[i - 1][1]) + 1;
      a[i][2] = a[i - 1][2];
      a[i][3] = max(a[i - 1][2], a[i - 1][3]) + 1;
    }
  }
  int s = 0;
  for (int i = 1; i <= n; i++)
    s = max(max(s, max(a[i][0], a[i][1])), max(s, max(a[i][2], a[i][3])));
  cout << s;
}
