#include <bits/stdc++.h>
using namespace std;
int n;
int a[2011], cnt[2][2011];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), cnt[0][i] = cnt[0][i - 1] + (a[i] == 1),
                        cnt[1][i] = cnt[1][i - 1] + (a[i] == 2);
  int ans = 0;
  for (int i = n; i; i--) {
    int f1 = 0, f2 = 0;
    for (int j = i; j; j--) {
      if (a[j] == 1)
        f1++;
      else
        f2 = max(f2, f1) + 1;
      ans = max(ans, max(f2, f1) + cnt[0][j - 1] + cnt[1][n] - cnt[1][i]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
