#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int n;
int main() {
  cin >> n;
  static int f[4], g[4];
  for (int i = 1, x; i <= n; i++) {
    scanf("%d", &x);
    g[0] = f[0] + (x == 1);
    g[1] = max(f[0], f[1]) + (x == 2);
    g[2] = max(f[1], f[2]) + (x == 1);
    g[3] = max(f[2], f[3]) + (x == 2);
    swap(f, g);
  }
  cout << max({f[0], f[1], f[2], f[3]});
  return 0;
}
